Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3008482imu; Wed, 7 Nov 2018 03:31:02 -0800 (PST) X-Google-Smtp-Source: AJdET5dB+doluiY2uAWeZH2RJj25F1XkXYLxjtLkLFpfn3UqiWXYiqKv8AMYqLE7VdJvwdMQIiB0 X-Received: by 2002:a63:ff16:: with SMTP id k22mr1244424pgi.244.1541590262032; Wed, 07 Nov 2018 03:31:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1541590261; cv=none; d=google.com; s=arc-20160816; b=JvOi0L0nbIo9ErsIvrP/aIRnirtPDt+6g+3bWQ00ZG1kb4k3DMHsq14nQ2f59/xxrn slbazEMzZ4K+hiE2lFYfS/WhGf4fqMQRoBt/5afOvhShRYNWsW9flsE3u6bq2dosimFZ dErn8CBuqYF9h9w55mELSUmr3vO0GJMAGJInsDR6BC20Lu/dezFz04HpUggiEgCWx4qk svfUwW21nO0J8dewJ7IStcZ99w1PC5PEpkoiWrvGaOukYJv3MPj1wxkJMOqrHb3yufp7 R6W2du5tlbBgJJQBu5CpgiIMtFl9L/BkUcEHy3N9Aby/g9sml4c3kyY04Cuupl+pkTZy MIwQ== 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=pLLp4RaPKrdi0AtRHL3b5EFHH4z590A+g/roEk/N8p4=; b=kP/EJzOdHXWjDH2yQLQOws0ueqeA5GL5KekoZrN19YmMxViKZBXts9tgt01+aOyybf z71RcpNlz1LcwRrU+9n92Zepu/6cipIlji55RewuFR96yNHg3TVNQPDOrPLcbvndlgUF SsLxLEZqhibsRQsFc6CONE94DQTHFJzXIQO+zC2nlqvwx0zFKejxlVIqkquOv/NbJYNW Xw9OSz57RCGOViPK0sKTLFlk81ifT3spLYPsLqwNYAMzVn08ROyi6Rr7Qn6rXY9J8UmI FzYRIW6BgjAEUltEig9Q/VDjQUqeNve5th6a1vfb8v97e7ToL7yjGAPmpMP9F5Ogz6W/ MqUQ== 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 a91-v6si361309pld.375.2018.11.07.03.30.44; Wed, 07 Nov 2018 03:31:01 -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 S1726687AbeKGVAS (ORCPT + 99 others); Wed, 7 Nov 2018 16:00:18 -0500 Received: from mx2.suse.de ([195.135.220.15]:41190 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1726248AbeKGVAS (ORCPT ); Wed, 7 Nov 2018 16:00:18 -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 44548ACB4; Wed, 7 Nov 2018 11:30:19 +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] x86/xen: fix pv boot Date: Wed, 7 Nov 2018 12:30:17 +0100 Message-Id: <20181107113017.30090-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 | 39 ++++++++++++++++++++++++++++++++++++--- arch/x86/xen/p2m.c | 3 +-- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h index 123e669bf363..a39015cb2f3f 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 @@ -91,15 +91,48 @@ clear_foreign_p2m_mapping(struct gnttab_unmap_grant_ref *unmap_ops, * Helper functions to write or read unsigned long values to/from * memory, when the access may fault. */ +#ifdef CONFIG_X86_32 +#define __i "l" +#define __r "k" +#else +#define __i "q" +#define __r "" +#endif 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"__i" %"__r"1,%2\n" + "2:\n" + ".section .fixup,\"ax\"\n" + "3: mov %3,%0\n" + " jmp 2b\n" + ".previous\n" + _ASM_EXTABLE(1b, 3b) + : "=r"(ret) + : "r" (val), "m" (*addr), "i" (-1), "0" (ret)); + return ret; } static inline int xen_safe_read_ulong(unsigned long *addr, unsigned long *val) { - return __get_user(*val, (unsigned long __user *)addr); + int ret = 0; + unsigned long rval; + + asm volatile("1: mov"__i" %2,%"__r"1\n" + "2:\n" + ".section .fixup,\"ax\"\n" + "3: mov %3,%0\n" + " jmp 2b\n" + ".previous\n" + _ASM_EXTABLE(1b, 3b) + : "=r" (ret), "=r" (rval) + : "m" (*addr), "i" (-1), "0" (ret)); + *val = rval; + return ret; } +#undef __i +#undef __r #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