From patchwork Fri Apr 28 09:51:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hou Wenlong X-Patchwork-Id: 88582 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp831822vqo; Fri, 28 Apr 2023 03:34:28 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ54LQ6x5AqcgnPpR9JQyYnfq3OIclMhODrXBla6PiUZCRv9zYwd8nUBezJGvLhKGDIBoAfk X-Received: by 2002:a17:90b:3b4f:b0:246:c223:14ba with SMTP id ot15-20020a17090b3b4f00b00246c22314bamr5084138pjb.28.1682678068587; Fri, 28 Apr 2023 03:34:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682678068; cv=none; d=google.com; s=arc-20160816; b=jEONbI7bfKu/L/6t+MU6e6hLkWu0l0RMyXKcVY60vlGURRv/GPxJ+g/Ro30nJtmBfV DWiM+VjYE/8XxIWBt4Y+mp2ZJ3eqIOMlvwCjx0xkrCkOhd1YV+weraBUvT3pNq1hnsWj QElltLHMV+Rpt55WjULe0qs/KP2nMezY5EWvmgkav7STO4vyFoLbUNXQClEv9/LKoAzw xUKR1U7UM0ToKM1Mc5mdVypJIqrQjNJ1VHg5CVXhB90KOXwPyuEJw9OaRYywd4lFDQMv hOJ+yuvtHLkJAbbOiZRuxgwsNMva72+WyaeyKbXw6r+lYUceD7T01Hapat9efwJcD7KB q33g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from; bh=qwWqFK68UPptgqSIXoptkzViwsruINWpsr9nlTvGRnk=; b=fmT9aycoWRJLO7dtAVDFgxv5Ut1ou/MRk+IvduYBsUinhSo24OB0iOpTuRvLvwTG3m fAnMWksDTjInWgk7VHFDdpJEwqZyjEHkfaIhg+DT0di5qF1CMpLoyg6hC7hlXF/AIobX Y3ZNoaaVQqx5W+FsxLC7SPuaHILqMXwSexqvML4BLvoy6Vad107JlRdsWll/RqogB3ew 5X1MRAw8nZPM7X8AQLJQhOfH+FZQN3llerZ9uQXOw3moHAvfiYo2z2hPNaicDsbapmit fcCwfZBjGdQFpB3V7EqgYtoGQImoH79JQGUr223+sHKBiiL0whxI63in/ydf0jv25/6z EaDQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id nn17-20020a17090b38d100b002478bba4da2si1956618pjb.127.2023.04.28.03.34.15; Fri, 28 Apr 2023 03:34:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=antgroup.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230159AbjD1J6t (ORCPT + 99 others); Fri, 28 Apr 2023 05:58:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35350 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1346021AbjD1J63 (ORCPT ); Fri, 28 Apr 2023 05:58:29 -0400 Received: from out187-24.us.a.mail.aliyun.com (out187-24.us.a.mail.aliyun.com [47.90.187.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9D52C6EAC for ; Fri, 28 Apr 2023 02:57:46 -0700 (PDT) X-Alimail-AntiSpam: AC=PASS;BC=-1|-1;BR=01201311R111e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=ay29a033018047206;MF=houwenlong.hwl@antgroup.com;NM=1;PH=DS;RN=14;SR=0;TI=SMTPD_---.STFoGhB_1682675630; Received: from localhost(mailfrom:houwenlong.hwl@antgroup.com fp:SMTPD_---.STFoGhB_1682675630) by smtp.aliyun-inc.com; Fri, 28 Apr 2023 17:53:50 +0800 From: "Hou Wenlong" To: linux-kernel@vger.kernel.org Cc: "Thomas Garnier" , "Lai Jiangshan" , "Kees Cook" , "Hou Wenlong" , "Juergen Gross" , "Boris Ostrovsky" , "Thomas Gleixner" , "Ingo Molnar" , "Borislav Petkov" , "Dave Hansen" , , "H. Peter Anvin" , Subject: [PATCH RFC 37/43] x86/xen: Pin up to VSYSCALL_ADDR when vsyscall page is out of fixmap area Date: Fri, 28 Apr 2023 17:51:17 +0800 Message-Id: <13975abd9b8b2e2e1e2efd3be6c341542b08af24.1682673543.git.houwenlong.hwl@antgroup.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1764415838216064354?= X-GMAIL-MSGID: =?utf-8?q?1764415838216064354?= If vsyscall page is moved out of fixmap area, then FIXADDR_TOP would be below vsyscall page. So it should pin up to VSYSCALL_ADDR if vsyscall is enabled. Suggested-by: Lai Jiangshan Signed-off-by: Hou Wenlong Cc: Thomas Garnier Cc: Kees Cook --- arch/x86/xen/mmu_pv.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/arch/x86/xen/mmu_pv.c b/arch/x86/xen/mmu_pv.c index a59bc013ee5b..28392f3478a0 100644 --- a/arch/x86/xen/mmu_pv.c +++ b/arch/x86/xen/mmu_pv.c @@ -587,6 +587,12 @@ static void xen_p4d_walk(struct mm_struct *mm, p4d_t *p4d, xen_pud_walk(mm, pud, func, last, limit); } +#ifdef CONFIG_X86_VSYSCALL_EMULATION +#define __KERNEL_MAP_TOP (VSYSCALL_ADDR + PAGE_SIZE) +#else +#define __KERNEL_MAP_TOP FIXADDR_TOP +#endif + /* * (Yet another) pagetable walker. This one is intended for pinning a * pagetable. This means that it walks a pagetable and calls the @@ -594,7 +600,7 @@ static void xen_p4d_walk(struct mm_struct *mm, p4d_t *p4d, * at every level. It walks the entire pagetable, but it only bothers * pinning pte pages which are below limit. In the normal case this * will be STACK_TOP_MAX, but at boot we need to pin up to - * FIXADDR_TOP. + * __KERNEL_MAP_TOP. * * We must skip the Xen hole in the middle of the address space, just after * the big x86-64 virtual hole. @@ -609,7 +615,7 @@ static void __xen_pgd_walk(struct mm_struct *mm, pgd_t *pgd, /* The limit is the last byte to be touched */ limit--; - BUG_ON(limit >= FIXADDR_TOP); + BUG_ON(limit >= __KERNEL_MAP_TOP); /* * 64-bit has a great big hole in the middle of the address @@ -797,7 +803,7 @@ static void __init xen_after_bootmem(void) #ifdef CONFIG_X86_VSYSCALL_EMULATION SetPagePinned(virt_to_page(level3_user_vsyscall)); #endif - xen_pgd_walk(&init_mm, xen_mark_pinned, FIXADDR_TOP); + xen_pgd_walk(&init_mm, xen_mark_pinned, __KERNEL_MAP_TOP); } static void xen_unpin_page(struct mm_struct *mm, struct page *page,