Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp2432444imj; Mon, 18 Feb 2019 06:01:27 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib120ONkyEkTXIBBP7lTIuiryNRnc1W8Q80ZXnVO0qOS95cDw/3XziiHatIcqzO9WS/Vv+X X-Received: by 2002:a63:1241:: with SMTP id 1mr9809243pgs.211.1550498487470; Mon, 18 Feb 2019 06:01:27 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550498487; cv=none; d=google.com; s=arc-20160816; b=LMoc9gmaHk3tB+tjbWW5O/xe/xy3aTtVdw0xl6Jjt5csxiQVuxE6mdsgpv8uapjUih lnNrnL5EwlhitZFZzGKSy+rUMN9/18FQEpCr3uWmo8i7kxp5gwozibqODIaXy+T06XRC V1JKzFFwZR6CUBHNf/0xqsiEU9/ktZHepcZzzBPibtYnP1BUaUcV9ZfXKfNZg4Q5NL6m fg5+hAmmvC4+lqlQ/7JZajPMbx0vBq1ZnV7+leq7M6Z8j5SA7xmJ65nj+t8k8S+1Zy8/ TupS54TMl7Y3d4+Ki2ocyVTZJPz1Sz6G9BlonTsxjB31+2mPaHq6TLBdG/Ak9sJxsvKS gCvg== 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=TgIhxO0g8FuputuIuIrgQ3INr1poq696jm7cGYRymx0=; b=FHFacc+B/Xvcit32Ub1ztamuEHVmYrFk1E5T92IaIcs2WvSTl7MwQVWh1u0pZUsRNY m9xoRicOzYeYvHyG51hfgITKyufyL1d2df+3YdpfjAz9NLiJbKhn6NQrgT33vhWGw9m4 zDRJHhxRnyqPKcLzLGevHL6YRekBPIPRvH1kzIa+yXZUZMG6jUG4usoz4LclY+yv77Zx 4mb63e+j5aMwKkCRVXr+oqaTPpRURbb805naBXT9S18R0etGs7GW9qoY6XWS50sOK22W exUeosimkKatLAuxLpGaKyjfqEFScgBkHaKVCX2KM2l+vsiSNnb047tKmj/EcBhyhhu9 kq2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=p9pIUZsR; 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 q16si13239354pgh.185.2019.02.18.06.01.11; Mon, 18 Feb 2019 06:01:27 -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=p9pIUZsR; 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 S2388813AbfBROAV (ORCPT + 99 others); Mon, 18 Feb 2019 09:00:21 -0500 Received: from mail.kernel.org ([198.145.29.99]:41502 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388780AbfBROAR (ORCPT ); Mon, 18 Feb 2019 09:00:17 -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 3A036217D9; Mon, 18 Feb 2019 14:00:15 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1550498415; bh=ABP7WavkDsRdNG5K0YIsKglktxL+rTpAHOOgENVTPo4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=p9pIUZsR2vPPatGEeyluKIbx+gwJziMqyYx4I99kTL0r99VDtn5RFt6VWsNVu3qdd 7E741CXwKEh4xT9Q+vLdvfdvK2aNbXdHOGViQDMLGuhoHDtbrd3RLzyrkOcReaQrR8 4nJSsTPxjzqJJSEWKVqaJ2O53NEP0Ob0ckOWFdx4= 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.9 47/58] x86/platform/UV: Use efi_runtime_lock to serialise BIOS calls Date: Mon, 18 Feb 2019 14:44:08 +0100 Message-Id: <20190218133512.176790600@linuxfoundation.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190218133508.567416115@linuxfoundation.org> References: <20190218133508.567416115@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.9-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)