Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp4167898pxf; Tue, 23 Mar 2021 04:36:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJ4Ngcplcda2YxnzNHoVvC2311W3cqK5P9jF7xxjXokJDtakSS4n/z5Pw7ay2OMhVX53AW X-Received: by 2002:a17:906:3c18:: with SMTP id h24mr4378993ejg.435.1616499386060; Tue, 23 Mar 2021 04:36:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1616499386; cv=none; d=google.com; s=arc-20160816; b=pJyE+HSrHTIEWDUcBfUNE0O6fAWnKsDI/JJKDZ+nFiw9xjjW5MTmVxv2y0oOwAt8G+ 4YvGKJJlReX1f92xl6T6Osy0cvNaGKMkM/lVV3K9KkwvgqRIqWZ9SDRu06xpfMW6QzA2 RqhZXUadPhZMbogeqGIncPYe2hGPw+OUd82lT8TtT25zrh/OL5ebEW3d4UtZ+Qg4K83q y0EvBKHEDLkNu0oK1ezQwxek9wyl0J1KWsnGyqgMvb9y/6Ypk8bb01+/8WovSJ7TRJ82 5SGc964PLrVDaayANo3Gg9H5SCXUEgLTyHSYBYuUTV+ouiuaozD6BSDLMSq41P+4yNgD lgiw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Sx96tZdFzleJmckps5BrYhpq4EiEUeB9mDj5nietAwc=; b=o/4g7uLhYAJ0IcvLFoiiFCi44mRU9Gx6XsvsZXjWyr16Y9XDFtnii2XlzD6uj8y2EF EHhMUxDuKEPUQFgydfn8j6k2inOWZr/ABxakPm0fKyM+jn5CylDvfSb1zc4txR2Xx7l+ LRWm7VS9c+JploD7iZgiR62HYnkkN1jG07T9oiWqevlf5CG6zUYsPUUYmWOGCQ4PQkV3 qrwCHpP21dxWLEVL5QfsXA3r6+G6WJ3eIa05l9ZaqEIYPsQmAPvKyY+hmnzKlpsCh4v2 7fIIssOJppCXdxTpiHkPynqvvdS7rb7h+sZLeVfp21V13dTBPoCZ0J8jpx9MYpA7TO1i d1pw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id de22si13233631edb.314.2021.03.23.04.36.03; Tue, 23 Mar 2021 04:36:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229482AbhCWLfF (ORCPT + 99 others); Tue, 23 Mar 2021 07:35:05 -0400 Received: from mail-wm1-f43.google.com ([209.85.128.43]:55894 "EHLO mail-wm1-f43.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbhCWLeb (ORCPT ); Tue, 23 Mar 2021 07:34:31 -0400 Received: by mail-wm1-f43.google.com with SMTP id 12so10847694wmf.5; Tue, 23 Mar 2021 04:34:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=Sx96tZdFzleJmckps5BrYhpq4EiEUeB9mDj5nietAwc=; b=VLJE43x/D6um2I2ZS3MJso1bDCY7siKL/DkaaWz3L5FFTJjKajv9qqaR32vb7ujcqm Z0OerjueE7fqfATtG7g9Ho/YSM2y1kfUSfw4nyl+p3kvC+pCQxzK6ufrUX2c/OrvXNmQ M38UXJtzShNGoWMuKA4Ufnb0BL3p6MUKIbyu7qex5IyeOXD5sUTOAMj3X48zeMRo98Nf GJ5i59aIb87hccUrHHvRlnFcMxuslbMDfkunQ2AiS0CG1MsUrNX8kL6q+ZrDxOLjHowc sjpNK6U+jmOFWUcRZmGy1ajdVyMatbzUfOEyhJrCjvwHJzqkj1lLsfMotDIqAJrG9tmN HaNw== X-Gm-Message-State: AOAM532FNrzHX5Zc0J+ML2ic9tMqvgTnKAZY8aDjmtFlmghYnAPt7W85 lKE63EQqN4PJwxXELsd7BHWdwarKeU0= X-Received: by 2002:a1c:4b15:: with SMTP id y21mr3003900wma.94.1616499270661; Tue, 23 Mar 2021 04:34:30 -0700 (PDT) Received: from liuwe-devbox-debian-v2 ([51.145.34.42]) by smtp.gmail.com with ESMTPSA id u17sm2226301wmq.3.2021.03.23.04.34.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 23 Mar 2021 04:34:30 -0700 (PDT) Date: Tue, 23 Mar 2021 11:34:29 +0000 From: Wei Liu To: Ingo Molnar Cc: Michael Kelley , Xu Yihang , KY Srinivasan , Haiyang Zhang , Stephen Hemminger , "tglx@linutronix.de" , "mingo@redhat.com" , "bp@alien8.de" , "x86@kernel.org" , "linux-hyperv@vger.kernel.org" , "linux-kernel@vger.kernel.org" , "johnny.chenyi@huawei.com" , "heying24@huawei.com" , Wei Liu Subject: Re: [PATCH -next] x86: Fix unused variable 'msr_val' warning Message-ID: <20210323113429.zj64itbfpqkruval@liuwe-devbox-debian-v2> References: <20210322031713.23853-1-xuyihang@huawei.com> <20210322210828.GA1961861@gmail.com> <20210323001303.GA3092649@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20210323001303.GA3092649@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Mar 23, 2021 at 01:13:03AM +0100, Ingo Molnar wrote: > > * Michael Kelley wrote: > > > From: Ingo Molnar Sent: Monday, March 22, 2021 2:08 PM > > > > > > * Xu Yihang wrote: > > > > > > > Fixes the following W=1 kernel build warning(s): > > > > arch/x86/hyperv/hv_spinlock.c:28:16: warning: variable 'msr_val' set but not used [- > > > Wunused-but-set-variable] > > > > unsigned long msr_val; > > > > > > > > As Hypervisor Top-Level Functional Specification states in chapter 7.5 Virtual Processor > > > Idle Sleep State, "A partition which possesses the AccessGuestIdleMsr privilege (refer to > > > section 4.2.2) may trigger entry into the virtual processor idle sleep state through a read to > > > the hypervisor-defined MSR HV_X64_MSR_GUEST_IDLE". That means only a read is > > > necessary, msr_val is not uesed, so __maybe_unused should be added. > > > > > > > > Reference: > > > > > > > > https://docs.microsoft.com/en-us/virtualization/hyper-v-on-windows/reference/tlfs > > > > > > > > Reported-by: Hulk Robot > > > > Signed-off-by: Xu Yihang > > > > --- > > > > arch/x86/hyperv/hv_spinlock.c | 2 +- > > > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > > > > > diff --git a/arch/x86/hyperv/hv_spinlock.c b/arch/x86/hyperv/hv_spinlock.c > > > > index f3270c1fc48c..67bc15c7752a 100644 > > > > --- a/arch/x86/hyperv/hv_spinlock.c > > > > +++ b/arch/x86/hyperv/hv_spinlock.c > > > > @@ -25,7 +25,7 @@ static void hv_qlock_kick(int cpu) > > > > > > > > static void hv_qlock_wait(u8 *byte, u8 val) > > > > { > > > > - unsigned long msr_val; > > > > + unsigned long msr_val __maybe_unused; > > > > unsigned long flags; > > > > > > Please don't add new __maybe_unused annotations to the x86 tree - > > > improve the flow instead to help GCC recognize the initialization > > > sequence better. > > > > > > Thanks, > > > > > > Ingo > > > > Could you elaborate on the thinking here, or point to some written > > discussion? I'm just curious. In this particular case, it's not a problem > > with the flow or gcc detection. This code really does read an MSR and > > ignore that value that is read, so it's not clear how gcc would ever > > figure out that's OK. > > Yeah, so the canonical way to signal that the msr_val isn't used would > be to rewrite this as: > > > if (READ_ONCE(*byte) == val) { > unsigned long msr_val; > > rdmsrl(HV_X64_MSR_GUEST_IDLE, msr_val); > > (void)msr_val; > } > > (Also see the patch below - untested.) > > This makes it abundantly clear that the rdmsr() msr_val return value > is not 'maybe' unused, but totally intentionally skipped. > > Thanks, > > Ingo > Thank you for the advice, Ingo. Wei.