Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1236352pxb; Wed, 27 Oct 2021 23:11:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyYGWm4wAb3o1hbl2JxFZKiRgOZ5UbL4gyGbo1E9Oa1kul2j+Fn1PiGPBEOZpVp/TN6hpNP X-Received: by 2002:a05:6402:2756:: with SMTP id z22mr3447158edd.167.1635401467846; Wed, 27 Oct 2021 23:11:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635401467; cv=none; d=google.com; s=arc-20160816; b=LzYsb1DnPuCXqg6MM8N+zXsmenA8Z+JVi7O/RsZcrzk+lhtmvLDgOA04sJdiUd3Inh tO9e4bv/CJHsMDy/Z5rn4uuLGNho4fIzf/mC4dZlTN7Q4xgCnQjdhJGHuGIX7nZUJ2Z5 Pk4LUIIS0Z3qCm1Sh6qZA3FlFsno1YftCGVjCaUV+GShmLo0BFtV6AGjxWQtgPD4KdbU WIkjzDHnmL4bowqIPLYb1DRW3ydUEBxIzXcu3TnonB/QEn6c/hI+oEJdpgvN8R0Mcwz4 daLY1KIF2vMyohHg6HnUmJVRcJlfzaruQjIg4JdA/ABidTg62VMnva/Q7pXZt0uZoK/Y n47Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:date:cc:to:from:subject :message-id:dkim-signature; bh=QW1VwJpwnVmxxU7z0qT05ZJcs1uisimu/KzjDIJrxzY=; b=gYWCmRag8Nj4ri6C9SjEvNsJS6FuWwJZLj9+eoXs3hZjqOncZF1Uw1+0LVc1bIrHpH SJEJogut+yqtd9HDNOllKDjzCLpmvL9sni6EwsfdZTl0k5qnqZtnIe3p3LTH5D8MqVxO kRUhKhr2U4uWpwG8T+H7ZVI5TkvGCHdH6RZ9X0c/0Jp3ZntOm4xyK5DGyjBuR+tRg10D gwmixvp058pCSGSWEBUYSmYRidG0pyFYK51r0txXg0U1Kaq7YCCmu0Vr1OtrjiJFI5Jn OESymAxeA0AIKT1EktiAIKdsj/TCXwKR+8r0OV6NlWyqN87aFQ7LKySMWHcWDVtUXBk+ 38qQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BdV35ORx; 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=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id f23si2310328edy.527.2021.10.27.23.10.40; Wed, 27 Oct 2021 23:11:07 -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; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=BdV35ORx; 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=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229778AbhJ1GJA (ORCPT + 99 others); Thu, 28 Oct 2021 02:09:00 -0400 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]:43291 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229586AbhJ1GI6 (ORCPT ); Thu, 28 Oct 2021 02:08:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1635401191; 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=QW1VwJpwnVmxxU7z0qT05ZJcs1uisimu/KzjDIJrxzY=; b=BdV35ORxvsi1jbUs1zapl/5uYM+tiiKGcYwgl5nC3sZd7E8nh6n0L0WwUHs+A2HHxWJXmE yfOssB64RjV6/QuFyEGL9sMzC/D233jdpls8LIjHNCnP1BPyhneNB3g01W7uMqfA+x7PxN 3EcuJNhJ0ywqY1HjC+I9e3MI10jr+O8= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-575-FpD08W43OridSh2IluPe8g-1; Thu, 28 Oct 2021 02:06:25 -0400 X-MC-Unique: FpD08W43OridSh2IluPe8g-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 2367679EEF; Thu, 28 Oct 2021 06:06:17 +0000 (UTC) Received: from starship (unknown [10.40.194.243]) by smtp.corp.redhat.com (Postfix) with ESMTP id 9A8DC70953; Thu, 28 Oct 2021 06:05:36 +0000 (UTC) Message-ID: <49c6c208841a85dbcb397acdc7f20b81402e71fb.camel@redhat.com> Subject: Re: [PATCH v2 23/43] KVM: VMX: Use boolean returns for Posted Interrupt "test" helpers From: Maxim Levitsky To: Sean Christopherson , Marc Zyngier , Huacai Chen , Aleksandar Markovic , Paul Mackerras , Anup Patel , Paul Walmsley , Palmer Dabbelt , Albert Ou , Christian Borntraeger , Janosch Frank , Paolo Bonzini Cc: James Morse , Alexandru Elisei , Suzuki K Poulose , Atish Patra , David Hildenbrand , Cornelia Huck , Claudio Imbrenda , Vitaly Kuznetsov , Wanpeng Li , Jim Mattson , Joerg Roedel , linux-arm-kernel@lists.infradead.org, kvmarm@lists.cs.columbia.edu, linux-mips@vger.kernel.org, kvm@vger.kernel.org, kvm-ppc@vger.kernel.org, kvm-riscv@lists.infradead.org, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, David Matlack , Oliver Upton , Jing Zhang Date: Thu, 28 Oct 2021 09:05:35 +0300 In-Reply-To: <20211009021236.4122790-24-seanjc@google.com> References: <20211009021236.4122790-1-seanjc@google.com> <20211009021236.4122790-24-seanjc@google.com> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.36.5 (3.36.5-2.fc32) MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 2021-10-08 at 19:12 -0700, Sean Christopherson wrote: > Return bools instead of ints for the posted interrupt "test" helpers. > The bit position of the flag being test does not matter to the callers, > and is in fact lost by virtue of test_bit() itself returning a bool. > > Returning ints is potentially dangerous, e.g. "pi_test_on(pi_desc) == 1" > is safe-ish because ON is bit 0 and thus any sane implementation of > pi_test_on() will work, but for SN (bit 1), checking "== 1" would rely on > pi_test_on() to return 0 or 1, a.k.a. bools, as opposed to 0 or 2 (the > positive bit position). > > Signed-off-by: Sean Christopherson > --- > arch/x86/kvm/vmx/posted_intr.c | 4 ++-- > arch/x86/kvm/vmx/posted_intr.h | 6 +++--- > 2 files changed, 5 insertions(+), 5 deletions(-) > > diff --git a/arch/x86/kvm/vmx/posted_intr.c b/arch/x86/kvm/vmx/posted_intr.c > index 6c2110d91b06..1688f8dc535a 100644 > --- a/arch/x86/kvm/vmx/posted_intr.c > +++ b/arch/x86/kvm/vmx/posted_intr.c > @@ -185,7 +185,7 @@ int pi_pre_block(struct kvm_vcpu *vcpu) > new.control) != old.control); > > /* We should not block the vCPU if an interrupt is posted for it. */ > - if (pi_test_on(pi_desc) == 1) > + if (pi_test_on(pi_desc)) > __pi_post_block(vcpu); > > local_irq_enable(); > @@ -216,7 +216,7 @@ void pi_wakeup_handler(void) > blocked_vcpu_list) { > struct pi_desc *pi_desc = vcpu_to_pi_desc(vcpu); > > - if (pi_test_on(pi_desc) == 1) > + if (pi_test_on(pi_desc)) > kvm_vcpu_kick(vcpu); > } > spin_unlock(&per_cpu(blocked_vcpu_on_cpu_lock, cpu)); > diff --git a/arch/x86/kvm/vmx/posted_intr.h b/arch/x86/kvm/vmx/posted_intr.h > index 7f7b2326caf5..36ae035f14aa 100644 > --- a/arch/x86/kvm/vmx/posted_intr.h > +++ b/arch/x86/kvm/vmx/posted_intr.h > @@ -40,7 +40,7 @@ static inline bool pi_test_and_clear_on(struct pi_desc *pi_desc) > (unsigned long *)&pi_desc->control); > } > > -static inline int pi_test_and_set_pir(int vector, struct pi_desc *pi_desc) > +static inline bool pi_test_and_set_pir(int vector, struct pi_desc *pi_desc) > { > return test_and_set_bit(vector, (unsigned long *)pi_desc->pir); > } > @@ -74,13 +74,13 @@ static inline void pi_clear_sn(struct pi_desc *pi_desc) > (unsigned long *)&pi_desc->control); > } > > -static inline int pi_test_on(struct pi_desc *pi_desc) > +static inline bool pi_test_on(struct pi_desc *pi_desc) > { > return test_bit(POSTED_INTR_ON, > (unsigned long *)&pi_desc->control); > } > > -static inline int pi_test_sn(struct pi_desc *pi_desc) > +static inline bool pi_test_sn(struct pi_desc *pi_desc) > { > return test_bit(POSTED_INTR_SN, > (unsigned long *)&pi_desc->control); Reviewed-by: Maxim Levitsky Best regards, Maxim Levitsky