Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3352835imu; Wed, 7 Nov 2018 09:02:03 -0800 (PST) X-Google-Smtp-Source: AJdET5eMavqwXIJ5RoUK+KnLE+zckSksaOGH9IZt9gZtVuTtl98OtGB7jBki5zufcTJw23ET1S7B X-Received: by 2002:a17:902:1105:: with SMTP id d5-v6mr1061169pla.28.1541610123163; Wed, 07 Nov 2018 09:02:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541610123; cv=none; d=google.com; s=arc-20160816; b=ZJvpabsgPIraCSc5WYYjhydPeNXugLvrk5/UhdtTzOhfxfBKVya+27bGo0WkeM9PJp ePZoLWK469my2Es0AXAR4wZQHcoHj/IlpMZVqugyeqvuSxlqPVSlFnZl/hj/adcRAqcO L/9/mJgHuEHOibk6rKhq00NrAnKM6/TjqGDybTARBpFyjqthiID5Z+JcUX1O/N3+eaw7 3gFZajxUeVS1jjUj4a2Sql6fqZTRIjTV99v1cv2ZP0pv5UEwzaMxaFHHrIcMRrucMpTg RQz5IP0pIGbKln6fhGhD1eejZ01WjzzyXfPBl67DmvKbJahlh75ytHWaPgDETZsKvzzt wgIg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:date:subject:cc:to:from; bh=1tJmP4cRJG9OLKassYt0WzV/vQmvXFzP42ucwOeM5rg=; b=CmEOUcj0Fm0ryAUpHKv8Xh2ayG5kx7yDA1xGNVJdTLp2VUChepoVc8Y6SxtRO8eeVg RDOJdZjn6eYLg8Yl5jEmYcSymg76Bgpo5r8dkkj1fp+0Qw5ChhL5ZUHNy35NFSWLXfHZ fTYtrJV5HFkd2l1isWcjtBrp+opB80ow7XnOek9rOdNOqBd1aPiTbmwXBGdLsmoo+S4C QJeTRAVqbp42GTfnDG1Iick51oWi/nQnYzelxZTVxA0TPzUdQNL1cOBtzSgaSyADQkbt cKyBCdFTxB1BVfpSsaykm8ilHczV07SzLu2/eshFQn4AvjPd1T04+h+xJ0KGRdx/Nawr 3JtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a5-v6si1127180plp.132.2018.11.07.09.01.47; Wed, 07 Nov 2018 09:02:03 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728144AbeKHCcQ (ORCPT + 99 others); Wed, 7 Nov 2018 21:32:16 -0500 Received: from mx2.suse.de ([195.135.220.15]:41874 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727699AbeKHCcQ (ORCPT ); Wed, 7 Nov 2018 21:32:16 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay1.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 3B2DEB6C6; Wed, 7 Nov 2018 17:01:02 +0000 (UTC) From: Juergen Gross To: linux-kernel@vger.kernel.org, xen-devel@lists.xenproject.org, x86@kernel.org Cc: boris.ostrovsky@oracle.com, sstabellini@kernel.org, hpa@zytor.com, tglx@linutronix.de, mingo@redhat.com, bp@alien8.de, Juergen Gross Subject: [PATCH v2] x86/xen: fix pv boot Date: Wed, 7 Nov 2018 18:01:00 +0100 Message-Id: <20181107170100.9435-1-jgross@suse.com> X-Mailer: git-send-email 2.16.4 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Commit 9da3f2b7405440 ("x86/fault: BUG() when uaccess helpers fault on kernel addresses") introduced a regression for booting Xen PV guests. Xen PV guests are using __put_user() and __get_user() for accessing the p2m map (physical to machine frame number map) as accesses might fail in case of not populated areas of the map. With above commit using __put_user() and __get_user() for accessing kernel pages is no longer valid. So replace the Xen hack by adding appropriate p2m access functions using the default fixup handler. Fixes: 9da3f2b7405440 ("x86/fault: BUG() when uaccess helpers fault on kernel addresses") Signed-off-by: Juergen Gross --- arch/x86/include/asm/xen/page.h | 35 +++++++++++++++++++++++++++++++---- arch/x86/xen/p2m.c | 3 +-- 2 files changed, 32 insertions(+), 6 deletions(-) diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h index 123e669bf363..790ce08e41f2 100644 --- a/arch/x86/include/asm/xen/page.h +++ b/arch/x86/include/asm/xen/page.h @@ -9,7 +9,7 @@ #include #include -#include +#include #include #include @@ -93,12 +93,39 @@ clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops, */ static inline int xen_safe_write_ulong(unsigned long *addr, unsigned long val) { - return __put_user(val, (unsigned long __user *)addr); + int ret = 0; + + asm volatile("1: mov %[val], %[ptr]\n" + "2:\n" + ".section .fixup, \"ax\"\n" + "3: sub $1, %[ret]\n" + " jmp 2b\n" + ".previous\n" + _ASM_EXTABLE(1b, 3b) + : [ret] "+r" (ret), [ptr] "=m" (*addr) + : [val] "r" (val)); + + return ret; } -static inline int xen_safe_read_ulong(unsigned long *addr, unsigned long *val) +static inline int xen_safe_read_ulong(const unsigned long *addr, + unsigned long *val) { - return __get_user(*val, (unsigned long __user *)addr); + int ret = 0; + unsigned long rval = ~0ul; + + asm volatile("1: mov %[ptr], %[rval]\n" + "2:\n" + ".section .fixup, \"ax\"\n" + "3: sub $1, %[ret]\n" + " jmp 2b\n" + ".previous\n" + _ASM_EXTABLE(1b, 3b) + : [ret] "+r" (ret), [rval] "+r" (rval) + : [ptr] "m" (*addr)); + *val = rval; + + return ret; } #ifdef CONFIG_XEN_PV diff --git a/arch/x86/xen/p2m.c b/arch/x86/xen/p2m.c index b06731705529..055e37e43541 100644 --- a/arch/x86/xen/p2m.c +++ b/arch/x86/xen/p2m.c @@ -656,8 +656,7 @@ bool __set_phys_to_machine(unsigned long pfn, unsigned long mfn) /* * The interface requires atomic updates on p2m elements. - * xen_safe_write_ulong() is using __put_user which does an atomic - * store via asm(). + * xen_safe_write_ulong() is using an atomic store via asm(). */ if (likely(!xen_safe_write_ulong(xen_p2m_addr + pfn, mfn))) return true; -- 2.16.4