Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp2575303iob; Sat, 30 Apr 2022 12:26:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy+wWdrx/BZNEvffX+TpHE5c20s2U3AhgI10ASpsuIOE6EFHxgQZjTsqve96f+aku2CMkp9 X-Received: by 2002:a17:903:11c5:b0:15e:7b29:b47d with SMTP id q5-20020a17090311c500b0015e7b29b47dmr4961638plh.21.1651346793422; Sat, 30 Apr 2022 12:26:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651346793; cv=none; d=google.com; s=arc-20160816; b=pFAC0A8nImMqQp3RMm0yjoX3fSywhlwsJs2r69zmpggVjhVt46sJIv0P9faD2n1f1H L1rO7ujxtVUUUuTK8m6Ub8XLFWanZEPRCBRnKqW9h/oaisKBf4TVHFG+7s61jpuxboTh DGruLQqF8l/OIDgRfj++xhQ0K6iFVKWfDvb31hYBvvxe0SwPfzvaCeAchnr8sCddPI7y 7X2dZ9YEJoRKOWojuzf0GB8nY3On4wflCqt3Z3CDIUjRp6AfR19+9VM3s2bTBIEOCcBS qUOMncmYaVjAF3cglM353qCwjJRjReSaKhKEPPYHl3Znx6DngOtaieJub25ZRnZTZ+/B 89AA== 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-transfer-encoding :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=pu2kafg8s3Dpw8thSMePtydoo2e/yB3JPGTXgTvagKs=; b=jKCvWbSTZ9Ho4a44q2kVgQtq79xL62O4lnHkzhuLR/ch9bG7VQy6Ar2aMP1JCB9kvO nUwwJbqiYQNySmu2BNyCkzgyaNC0d1OB6EK6YlVKK09SOGlv0ALnUJ3khZoZb/loGg8b Hf+fIzEuH4872WMlDAvv5fMnhfVvB+pV9hxjClb3/H32yAaTO2QuC/gSUBQ8sKkytoEH YRTCyq6BT3m4qxXjlK9mOcwDkkYQzv50tkhP8ujzqi8dUQnYIzhfWTYdkqUN9lP2D7Ze fZWT5S9Bc9trzo6xAIcv1nYGa9gBOytOmRLTUqibZplSnGpfZgMm5Q75T7f4DxZo7GHs nahg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YRWdx1Ex; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h70-20020a638349000000b003c1f4372e8asi608400pge.31.2022.04.30.12.26.07; Sat, 30 Apr 2022 12:26:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=YRWdx1Ex; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231889AbiD1LHR (ORCPT + 99 others); Thu, 28 Apr 2022 07:07:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230363AbiD1LHQ (ORCPT ); Thu, 28 Apr 2022 07:07:16 -0400 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 3824C187 for ; Thu, 28 Apr 2022 04:04:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1651143840; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=pu2kafg8s3Dpw8thSMePtydoo2e/yB3JPGTXgTvagKs=; b=YRWdx1Ex33CotqSvMURQm16VI/xTbwe5CKv1syW2uItuieZLL32dXIzXjHDkGpOHvyivqX lvbWTqqyhHwQORswrUM3sjumfF+fLcs2TE3CfJFo3qQcMXbVnr3mE9npg2TM4dwDJM2nmA pDbycwSQMvwqU+Ms17YJNyIY9tzZRrs= Received: from mail-wm1-f70.google.com (mail-wm1-f70.google.com [209.85.128.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-661-HcEpPW9gOyi7DFrJ3qREJw-1; Thu, 28 Apr 2022 07:03:58 -0400 X-MC-Unique: HcEpPW9gOyi7DFrJ3qREJw-1 Received: by mail-wm1-f70.google.com with SMTP id h65-20020a1c2144000000b0038e9ce3b29cso4234255wmh.2 for ; Thu, 28 Apr 2022 04:03:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:content-transfer-encoding :in-reply-to; bh=pu2kafg8s3Dpw8thSMePtydoo2e/yB3JPGTXgTvagKs=; b=fejUUMTQHQaqNaJbclzwqMOXQllN4C9rbCCX+EWN+B7J+GbJXUDM8wJUmdzbjKEpTg Dq52VikkfXhJDoX6KvP+9X/sCiwp8PhbaURWYnk06X4R6FB5aEwgRHt6r1eEvws9jDg/ FIReqbP5PIAPDVlU6bHUSiAenbRFONIqW67rkvRuV6miXMcIcZCyfZ+Q6F25f/JB5hzX g4T5jhwz396nuSUhUT+YxkUjK1QZg8wv8SBlZg+9WZoAqDXPjD9mfkfoEc7xMvEtlCOB y6SRtyeiz2wBNV0SGVxqz6GWFsMxaxMgQE8OHWnQgCG8KA2C4vhqZfFgyxOIa0OQHW9s fmYA== X-Gm-Message-State: AOAM5334OGTcEKmi/ir4SuYuVaMQJo/veONou0nkyQEIlyQAOIDrVI83 MoKSRXmRmqTkTkvS3f4gjtxmWWZFMo2Q/0lIzpOKg1HPEi19rPc4wZm5M7ze1orEAQ0ZgM8G6V7 h3nDoIIDeCw29J1YhBiagrNI3 X-Received: by 2002:a5d:6388:0:b0:20a:ed44:fd38 with SMTP id p8-20020a5d6388000000b0020aed44fd38mr7212097wru.153.1651143837709; Thu, 28 Apr 2022 04:03:57 -0700 (PDT) X-Received: by 2002:a5d:6388:0:b0:20a:ed44:fd38 with SMTP id p8-20020a5d6388000000b0020aed44fd38mr7212079wru.153.1651143837425; Thu, 28 Apr 2022 04:03:57 -0700 (PDT) Received: from redhat.com ([2.53.18.16]) by smtp.gmail.com with ESMTPSA id bg20-20020a05600c3c9400b0037fa5c422c8sm4205877wmb.48.2022.04.28.04.03.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Apr 2022 04:03:55 -0700 (PDT) Date: Thu, 28 Apr 2022 07:03:51 -0400 From: "Michael S. Tsirkin" To: Christophe Marie Francois Dupont de Dinechin Cc: Murilo Opsfelder Araujo , Jason Wang , virtualization@lists.linux-foundation.org, linux-kernel@vger.kernel.org, mopsfelder@gmail.com, Christophe de Dinechin Subject: Re: [PATCH] virtio-pci: Remove wrong address verification in vp_del_vqs() Message-ID: <20220428070345-mutt-send-email-mst@kernel.org> References: <20220415023002.49805-1-muriloo@linux.ibm.com> <2F2EFFE9-5174-49A8-A71F-EE134D387E07@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <2F2EFFE9-5174-49A8-A71F-EE134D387E07@redhat.com> X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, SPF_HELO_NONE,SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Thu, Apr 28, 2022 at 11:55:31AM +0200, Christophe Marie Francois Dupont de Dinechin wrote: > > > > On 28 Apr 2022, at 11:51, Christophe Marie Francois Dupont de Dinechin wrote: > > > > > > > >> On 28 Apr 2022, at 11:46, Christophe Marie Francois Dupont de Dinechin wrote: > >> > >> > >> > >>> On 15 Apr 2022, at 05:51, Murilo Opsfelder Araújo wrote: > >>> > >>> On 4/14/22 23:30, Murilo Opsfelder Araujo wrote: > >>>> GCC 12 enhanced -Waddress when comparing array address to null [0], > >>>> which warns: > >>>> drivers/virtio/virtio_pci_common.c: In function ‘vp_del_vqs’: > >>>> drivers/virtio/virtio_pci_common.c:257:29: warning: the comparison will always evaluate as ‘true’ for the pointer operand in ‘vp_dev->msix_affinity_masks + (sizetype)((long unsigned int)i * 256)’ must not be NULL [-Waddress] > >>>> 257 | if (vp_dev->msix_affinity_masks[i]) > >>>> | ^~~~~~ > >>>> In fact, the verification is comparing the result of a pointer > >>>> arithmetic, the address "msix_affinity_masks + i", which will always > >>>> evaluate to true. > >>>> Under the hood, free_cpumask_var() calls kfree(), which is safe to pass > >>>> NULL, not requiring non-null verification. So remove the verification > >>>> to make compiler happy (happy compiler, happy life). > >>>> [0] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102103 > >>>> Signed-off-by: Murilo Opsfelder Araujo > >>>> --- > >>>> drivers/virtio/virtio_pci_common.c | 3 +-- > >>>> 1 file changed, 1 insertion(+), 2 deletions(-) > >>>> diff --git a/drivers/virtio/virtio_pci_common.c b/drivers/virtio/virtio_pci_common.c > >>>> index d724f676608b..5046efcffb4c 100644 > >>>> --- a/drivers/virtio/virtio_pci_common.c > >>>> +++ b/drivers/virtio/virtio_pci_common.c > >>>> @@ -254,8 +254,7 @@ void vp_del_vqs(struct virtio_device *vdev) > >>>> if (vp_dev->msix_affinity_masks) { > >>>> for (i = 0; i < vp_dev->msix_vectors; i++) > >>>> - if (vp_dev->msix_affinity_masks[i]) > >>>> - free_cpumask_var(vp_dev->msix_affinity_masks[i]); > >>>> + free_cpumask_var(vp_dev->msix_affinity_masks[i]); > >>>> } > >>>> if (vp_dev->msix_enabled) { > >>> > >>> After I sent this message, I realized that Christophe (copied here) > >>> had already proposed a fix: > >>> > >>> https://lore.kernel.org/lkml/20220414150855.2407137-4-dinechin@redhat.com/ > >>> > >>> Christophe, > >>> > >>> Since free_cpumask_var() calls kfree() and kfree() is null-safe, > >>> can we just drop this null verification and call free_cpumask_var() right away? > >> > >> Apologies for the delay in responding, broken laptop… > >> > >> In the case where CONFIG_CPUMASK_OFFSTACK is not defined, we have: > >> > >> typedef struct cpumask cpumask_var_t[1]; > >> > >> So that vp_dev->msix_affinity_masks[i] is statically not null (that’s the warning) > >> but also a static pointer, so not kfree-safe IMO. > > > > … which also renders my own patch invalid :-/ > > > > Compiler warnings are good. Clearly not sufficient. > > Ah, I just noticed that free_cpumask_var is a noop in that case. > > So yes, your fix is better :-) ACK then?