From patchwork Thu Feb 20 06:23:18 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Kees Cook X-Patchwork-Id: 11393433 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5F5A114E3 for ; Thu, 20 Feb 2020 06:24:40 +0000 (UTC) Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 3B0CA24656 for ; Thu, 20 Feb 2020 06:24:40 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (1024-bit key) header.d=chromium.org header.i=@chromium.org header.b="KZPJA/xX" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3B0CA24656 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=chromium.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=xen-devel-bounces@lists.xenproject.org Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4fF4-0000Sx-OU; Thu, 20 Feb 2020 06:23:22 +0000 Received: from us1-rack-iad1.inumbo.com ([172.99.69.81]) by lists.xenproject.org with esmtp (Exim 4.89) (envelope-from ) id 1j4fF3-0000Ss-Vl for xen-devel@lists.xenproject.org; Thu, 20 Feb 2020 06:23:22 +0000 X-Inumbo-ID: 7d961a5c-53a9-11ea-b0fd-bc764e2007e4 Received: from mail-pj1-x1043.google.com (unknown [2607:f8b0:4864:20::1043]) by us1-rack-iad1.inumbo.com (Halon) with ESMTPS id 7d961a5c-53a9-11ea-b0fd-bc764e2007e4; Thu, 20 Feb 2020 06:23:21 +0000 (UTC) Received: by mail-pj1-x1043.google.com with SMTP id e9so430363pjr.4 for ; Wed, 19 Feb 2020 22:23:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pK6zifq3Fj1hZPmmtdvS+UBS/FWrDP/7PRY/z1oHHl8=; b=KZPJA/xXWgvj7+EDceNGW99DsMGfVsrwZtMNYFEQmEcfbi6t1Ltywm8yF3gRS+KFsW YYa/KruX+agIH6tt/eZGI71UjpwjuT3jsuFYNKw+P7dbnGut/vUuytmTV4wCLvbb1OWN mFx5qdjyKzEPpPz0IfGRUIg5ongLMg7FFfcz0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=pK6zifq3Fj1hZPmmtdvS+UBS/FWrDP/7PRY/z1oHHl8=; b=cEB9S8aIKqH0zoTjeE9VMtpHNCeHbhGAd/RZGnf5KgksZO92k1V+f9DcP2QvI1N0AF Hk1vSmOE6Vy3vIq+Y2S1JZl9QkRSHxAG4BPrqSwXNxMUwclbdQhZJxtv2g164iktZiPo 65BDH8gu68VBT2z9CUkbCm2Vdyff+20EP51STFf9F8ieL/a9OTTxfQkcJaANaSvpV89C mqRY6ehWJIQ7U9Oim9s1EuXMoIBRfQ5oHMSwNBAOQi9NkwV0iRgv5kh1TXjOnWY7nXMQ N1xfZCrR6SVdoFR6dDsZOwwVxJyxIBCYzzG22jCUPeUQYfnv5Fk0qWNxKEHvPT+HbMSx pgsA== X-Gm-Message-State: APjAAAW31zwB07iYOX0TzfeWiSnwOmDgcJyJmqlAtY35yfx1SF7CPHQP aPA60XqfYBnsbeMt72WwcBlEJw== X-Google-Smtp-Source: APXvYqx1kik6D0tY4SYKS7j1S0Bqg7hWpfmaq2nth5vTea0tU8wMl9ddGmg2GgyqqThc+95RG3/LrA== X-Received: by 2002:a17:90a:f316:: with SMTP id ca22mr1759190pjb.59.1582179800527; Wed, 19 Feb 2020 22:23:20 -0800 (PST) Received: from www.outflux.net (smtp.outflux.net. [198.145.64.163]) by smtp.gmail.com with ESMTPSA id 3sm1760480pfi.13.2020.02.19.22.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 19 Feb 2020 22:23:19 -0800 (PST) From: Kees Cook To: Boris Ostrovsky , Juergen Gross Date: Wed, 19 Feb 2020 22:23:18 -0800 Message-Id: <20200220062318.69299-1-keescook@chromium.org> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Xen-devel] [PATCH] x86/xen: Distribute switch variables for initialization X-BeenThere: xen-devel@lists.xenproject.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Cc: xen-devel@lists.xenproject.org, Stefano Stabellini , Alexander Potapenko , Kees Cook , linux-kernel@vger.kernel.org Errors-To: xen-devel-bounces@lists.xenproject.org Sender: "Xen-devel" Variables declared in a switch statement before any case statements cannot be automatically initialized with compiler instrumentation (as they are not part of any execution flow). With GCC's proposed automatic stack variable initialization feature, this triggers a warning (and they don't get initialized). Clang's automatic stack variable initialization (via CONFIG_INIT_STACK_ALL=y) doesn't throw a warning, but it also doesn't initialize such variables[1]. Note that these warnings (or silent skipping) happen before the dead-store elimination optimization phase, so even when the automatic initializations are later elided in favor of direct initializations, the warnings remain. To avoid these problems, move such variables into the "case" where they're used or lift them up into the main function body. arch/x86/xen/enlighten_pv.c: In function ‘xen_write_msr_safe’: arch/x86/xen/enlighten_pv.c:904:12: warning: statement will never be executed [-Wswitch-unreachable] 904 | unsigned which; | ^~~~~ [1] https://bugs.llvm.org/show_bug.cgi?id=44916 Signed-off-by: Kees Cook Reviewed-by: Juergen Gross --- arch/x86/xen/enlighten_pv.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/arch/x86/xen/enlighten_pv.c b/arch/x86/xen/enlighten_pv.c index 1f756ffffe8b..789dc12b7962 100644 --- a/arch/x86/xen/enlighten_pv.c +++ b/arch/x86/xen/enlighten_pv.c @@ -896,14 +896,15 @@ static u64 xen_read_msr_safe(unsigned int msr, int *err) static int xen_write_msr_safe(unsigned int msr, unsigned low, unsigned high) { int ret; +#ifdef CONFIG_X86_64 + unsigned which; + u64 base; +#endif ret = 0; switch (msr) { #ifdef CONFIG_X86_64 - unsigned which; - u64 base; - case MSR_FS_BASE: which = SEGBASE_FS; goto set; case MSR_KERNEL_GS_BASE: which = SEGBASE_GS_USER; goto set; case MSR_GS_BASE: which = SEGBASE_GS_KERNEL; goto set;