Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2468872imj; Mon, 18 Feb 2019 06:33:48 -0800 (PST) X-Google-Smtp-Source: AHgI3IaT00BvSJDljI7I86j9eUCL0ssOI4RKwOn4TAnMWOvQ84UkKzKr8NujRfMspJ86XKZbgXcS X-Received: by 2002:a17:902:42e4:: with SMTP id h91mr26006077pld.18.1550500428371; Mon, 18 Feb 2019 06:33:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550500428; cv=none; d=google.com; s=arc-20160816; b=LcVRAo8zYlgaSI4Ay70MktdsQsYZ12kvvJubjzajswiMWZtrywMPPCHfDD3E0ZGuq9 7x8Dh1u5vZT9wVVRBKjvEeTFp8yw3pdU3uomsHX2e54pccy/vZxWi3G60lZ+g7NqkW6E dW5HZIJjxsQbULjkm92yYiSoWeifHyAHJVKgp3SHxTtgzcjR0ld4fb0Q2t3qnzo70d7t aI8wUe0N5q1koQML5sPk+VwazHki+rtfZMmGCNR8MXmPPFlOKxJVZPwkgu73MmIJZw1H iiGRqsZMJSS9+SERxp+YVr4hlZCeud5Gs0p16FJvZpYTW4eqY6YMJeophZCGbHjduLtg A6fA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=kA1y2cQoCUiV0EWxfNXSOlj8S/gmLvGT4hbaw19ZXOU=; b=BcA3LZmzoWzv1+VklwEI71FUDBtRxCZxg98ZlncWGINd5gUqXkyIMg8G0Zdj9+Mhfz G5FqSwTEg89EmwlmbY+cHPByYik9ej/yDlFUYnRaK3TXTpM2GAXHWlm6/zADEkoZ7ZHM lgwoPkJpUfO5NbvB3qoIN5f5eWddN5IPdrJs5CFUtaAmkht97UjnVtY3tP7g1dtv8c5J APD6pUgZlnbi7i00czwTtMogXhOFHRDMa6Cl7aUcqnS0Vby4f2wqkiK1xr59K4EPbX+V 7sv0dMi+kct5wyPdTsvvuYUGUhrqdH/W1e2Ix3LPJ6AckryrlyNNzn2oO2GtbROwRMfx SfhA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=UK+9HX3j; 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 t18si5978329pgh.89.2019.02.18.06.33.32; Mon, 18 Feb 2019 06:33:48 -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; dkim=pass header.i=@kernel.org header.s=default header.b=UK+9HX3j; 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 S2387800AbfBROcr (ORCPT + 99 others); Mon, 18 Feb 2019 09:32:47 -0500 Received: from mail.kernel.org ([198.145.29.99]:37860 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388019AbfBRN50 (ORCPT ); Mon, 18 Feb 2019 08:57:26 -0500 Received: from localhost (5356596B.cm-6-7b.dynamic.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id B03B2217D9; Mon, 18 Feb 2019 13:57:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550498245; bh=anL+7f5/DRkgbWzrDz8wEjuVDr5L2Q8S4DG5QgLKe8Q=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UK+9HX3jBfHYBQa0N/WwwXVoQcWN8VpxQsxnawbWsRpUthp5m6WaH6GDm58NIR3dr KrmFxtdAyX1XLtbgCQw0tXOLgz5lwX92X7GAVab+IhUL6lsE7aSC+pcIrF8CY74Q5j 4gwEbrUbt4GmA8+lqlKBpgrimywQjnom/XiTNFr4= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Hedi Berriche , Borislav Petkov , Ard Biesheuvel , Russ Anderson , Dimitri Sivanich , Mike Travis , Andy Shevchenko , Bhupesh Sharma , Darren Hart , "H. Peter Anvin" , Ingo Molnar , linux-efi , platform-driver-x86@vger.kernel.org, Steve Wahl , Thomas Gleixner , x86-ml Subject: [PATCH 4.14 53/62] x86/platform/UV: Use efi_runtime_lock to serialise BIOS calls Date: Mon, 18 Feb 2019 14:43:59 +0100 Message-Id: <20190218133510.320971777@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218133505.801423074@linuxfoundation.org> References: <20190218133505.801423074@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review X-Patchwork-Hint: ignore MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.14-stable review patch. If anyone has any objections, please let me know. ------------------ From: Hedi Berriche commit f331e766c4be33f4338574f3c9f7f77e98ab4571 upstream. Calls into UV firmware must be protected against concurrency, expose the efi_runtime_lock to the UV platform, and use it to serialise UV BIOS calls. Signed-off-by: Hedi Berriche Signed-off-by: Borislav Petkov Reviewed-by: Ard Biesheuvel Reviewed-by: Russ Anderson Reviewed-by: Dimitri Sivanich Reviewed-by: Mike Travis Cc: Andy Shevchenko Cc: Bhupesh Sharma Cc: Darren Hart Cc: "H. Peter Anvin" Cc: Ingo Molnar Cc: linux-efi Cc: platform-driver-x86@vger.kernel.org Cc: stable@vger.kernel.org # v4.9+ Cc: Steve Wahl Cc: Thomas Gleixner Cc: x86-ml Link: https://lkml.kernel.org/r/20190213193413.25560-5-hedi.berriche@hpe.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/include/asm/uv/bios.h | 8 +++++++- arch/x86/platform/uv/bios_uv.c | 23 +++++++++++++++++++++-- drivers/firmware/efi/runtime-wrappers.c | 7 +++++++ 3 files changed, 35 insertions(+), 3 deletions(-) --- a/arch/x86/include/asm/uv/bios.h +++ b/arch/x86/include/asm/uv/bios.h @@ -48,7 +48,8 @@ enum { BIOS_STATUS_SUCCESS = 0, BIOS_STATUS_UNIMPLEMENTED = -ENOSYS, BIOS_STATUS_EINVAL = -EINVAL, - BIOS_STATUS_UNAVAIL = -EBUSY + BIOS_STATUS_UNAVAIL = -EBUSY, + BIOS_STATUS_ABORT = -EINTR, }; /* Address map parameters */ @@ -167,4 +168,9 @@ extern long system_serial_number; extern struct kobject *sgi_uv_kobj; /* /sys/firmware/sgi_uv */ +/* + * EFI runtime lock; cf. firmware/efi/runtime-wrappers.c for details + */ +extern struct semaphore __efi_uv_runtime_lock; + #endif /* _ASM_X86_UV_BIOS_H */ --- a/arch/x86/platform/uv/bios_uv.c +++ b/arch/x86/platform/uv/bios_uv.c @@ -29,7 +29,8 @@ struct uv_systab *uv_systab; -s64 uv_bios_call(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5) +static s64 __uv_bios_call(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3, + u64 a4, u64 a5) { struct uv_systab *tab = uv_systab; s64 ret; @@ -51,6 +52,19 @@ s64 uv_bios_call(enum uv_bios_cmd which, return ret; } + +s64 uv_bios_call(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3, u64 a4, u64 a5) +{ + s64 ret; + + if (down_interruptible(&__efi_uv_runtime_lock)) + return BIOS_STATUS_ABORT; + + ret = __uv_bios_call(which, a1, a2, a3, a4, a5); + up(&__efi_uv_runtime_lock); + + return ret; +} EXPORT_SYMBOL_GPL(uv_bios_call); s64 uv_bios_call_irqsave(enum uv_bios_cmd which, u64 a1, u64 a2, u64 a3, @@ -59,10 +73,15 @@ s64 uv_bios_call_irqsave(enum uv_bios_cm unsigned long bios_flags; s64 ret; + if (down_interruptible(&__efi_uv_runtime_lock)) + return BIOS_STATUS_ABORT; + local_irq_save(bios_flags); - ret = uv_bios_call(which, a1, a2, a3, a4, a5); + ret = __uv_bios_call(which, a1, a2, a3, a4, a5); local_irq_restore(bios_flags); + up(&__efi_uv_runtime_lock); + return ret; } --- a/drivers/firmware/efi/runtime-wrappers.c +++ b/drivers/firmware/efi/runtime-wrappers.c @@ -50,6 +50,13 @@ void efi_call_virt_check_flags(unsigned } /* + * Expose the EFI runtime lock to the UV platform + */ +#ifdef CONFIG_X86_UV +extern struct semaphore __efi_uv_runtime_lock __alias(efi_runtime_lock); +#endif + +/* * According to section 7.1 of the UEFI spec, Runtime Services are not fully * reentrant, and there are particular combinations of calls that need to be * serialized. (source: UEFI Specification v2.4A)