Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp1913441pxb; Mon, 23 Aug 2021 07:35:10 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzbnMC1XEl6qq1mY92QqaBol7gnL5iHa+HoyRqd33O+OnyblX5nZnfxleoCKmD2qfNVkq6j X-Received: by 2002:a05:6402:1d54:: with SMTP id dz20mr16687001edb.70.1629729310414; Mon, 23 Aug 2021 07:35:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1629729310; cv=none; d=google.com; s=arc-20160816; b=FTmY5GjuzDOeOkICuEUgK/C7iJuWNkntEHm79+8uHMJDaecW3EdGdVaF+37CSca/xz MyGuu32X2bPszXL2Gjab1qjPsK6j3ZlZyrG56n/zwiUW62w/mD6xmy7ITwVsHN+7DQn/ eF+jA5JHYbLRR7BShJ5Q0k8NZjQELIgVZxPp6qc+02SvXfEbhTL550U7UvtYdXkq5FtV CqRpcmPt1e9vnXIiybT12UONPhsikTOCJ4w8jzoxM06zqDbj2/0YBejCsBQPdysJAdW1 6pZi7oDoZ4xBf4ENXL0HptwGQicJLrETlPzH+Ox5DrttTu/HHpjAPgUmbyp2NgxlEeNz pyyA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=/WbznmYSWXy3CwdDh9G5nMXx6sTahDe95v+6YXmfShI=; b=J/pzcY6R5bsQN51xi7QvlT94/IiT7YaETi7K5uciwQQq5/YxhgAVOKa0HSIvMJ5wK7 Z+m+HKSVT4MqjcMTEaVikYE3cDdaBK681lRyZS5eEjFUnLjNuM7Jte3ibg/d4T9HL/AT hhCm+ZRTZz6xehMl6Rf+/H5GT3qFRX0ZaZx7axFHWhTaCOM8A2CpVxaz9HbpguiN8V0C z+cz2EMDnSSvzl+JEQ8o3loQHSmOHwfb0XHbrHwYcTRwNHpEvPJPOiXnSquVyg7dtEDD 5OpSZ42rjJvL2fC7h7pmu8ScIVGU4FcwZ3n3pNTClWSzBw7MkSJrdTLCZOjlIkvBbHKV 3kVg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=JpN7qj4O; 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 j7si18507524ejm.280.2021.08.23.07.34.45; Mon, 23 Aug 2021 07:35:10 -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=JpN7qj4O; 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 S230352AbhHWOce (ORCPT + 99 others); Mon, 23 Aug 2021 10:32:34 -0400 Received: from us-smtp-delivery-124.mimecast.com ([170.10.133.124]:52095 "EHLO us-smtp-delivery-124.mimecast.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230282AbhHWOcc (ORCPT ); Mon, 23 Aug 2021 10:32:32 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1629729109; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/WbznmYSWXy3CwdDh9G5nMXx6sTahDe95v+6YXmfShI=; b=JpN7qj4OYj2c/htc75vIkWUpGZ/teAkwLVhaQy+tyHPBD959DR/UEUz8yW45ZlA4sZSyEo jDz7V37tbZmCGsdDUuZ33/a9cvqsBo96vtIBCRgBjJqweHo2EA5qZXTjKTWi081zBiDn8O NckR3mTfVwjOKwPYkpdF+c6sMQp3jiA= 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-9-EA4ViK-VP-iBsqhJwEhxlw-1; Mon, 23 Aug 2021 10:30:43 -0400 X-MC-Unique: EA4ViK-VP-iBsqhJwEhxlw-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.phx2.redhat.com [10.5.11.23]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 0E2D5190B2A9; Mon, 23 Aug 2021 14:30:42 +0000 (UTC) Received: from vitty.brq.redhat.com (unknown [10.40.195.132]) by smtp.corp.redhat.com (Postfix) with ESMTP id 200342707F; Mon, 23 Aug 2021 14:30:39 +0000 (UTC) From: Vitaly Kuznetsov To: kvm@vger.kernel.org, Paolo Bonzini Cc: Sean Christopherson , Wanpeng Li , Jim Mattson , "Dr. David Alan Gilbert" , Nitesh Narayan Lal , linux-kernel@vger.kernel.org Subject: [PATCH v2 2/4] KVM: Guard cpusmask NULL check with CONFIG_CPUMASK_OFFSTACK Date: Mon, 23 Aug 2021 16:30:26 +0200 Message-Id: <20210823143028.649818-3-vkuznets@redhat.com> In-Reply-To: <20210823143028.649818-1-vkuznets@redhat.com> References: <20210823143028.649818-1-vkuznets@redhat.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Scanned-By: MIMEDefang 2.84 on 10.5.11.23 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Sean Christopherson Check for a NULL cpumask_var_t when kicking multiple vCPUs if and only if cpumasks are configured to be allocated off-stack. This is a meaningless optimization, e.g. avoids a TEST+Jcc and TEST+CMOV on x86, but more importantly helps document that the NULL check is necessary even though all callers pass in a local variable. No functional change intended. Signed-off-by: Sean Christopherson Signed-off-by: Vitaly Kuznetsov --- virt/kvm/kvm_main.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c index 786b914db98f..82c5280dd5ce 100644 --- a/virt/kvm/kvm_main.c +++ b/virt/kvm/kvm_main.c @@ -247,7 +247,7 @@ static void ack_flush(void *_completed) static inline bool kvm_kick_many_cpus(const struct cpumask *cpus, bool wait) { - if (unlikely(!cpus)) + if (IS_ENABLED(CONFIG_CPUMASK_OFFSTACK) && unlikely(!cpus)) cpus = cpu_online_mask; if (cpumask_empty(cpus)) @@ -277,6 +277,14 @@ bool kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, if (!(req & KVM_REQUEST_NO_WAKEUP) && kvm_vcpu_wake_up(vcpu)) continue; + /* + * tmp can be NULL if cpumasks are allocated off stack, as + * allocation of the mask is deliberately not fatal and is + * handled by falling back to kicking all online CPUs. + */ + if (IS_ENABLED(CONFIG_CPUMASK_OFFSTACK) && !tmp) + continue; + /* * Note, the vCPU could get migrated to a different pCPU at any * point after kvm_request_needs_ipi(), which could result in @@ -288,7 +296,7 @@ bool kvm_make_vcpus_request_mask(struct kvm *kvm, unsigned int req, * were reading SPTEs _before_ any changes were finalized. See * kvm_vcpu_kick() for more details on handling requests. */ - if (tmp != NULL && kvm_request_needs_ipi(vcpu, req)) { + if (kvm_request_needs_ipi(vcpu, req)) { cpu = READ_ONCE(vcpu->cpu); if (cpu != -1 && cpu != me) __cpumask_set_cpu(cpu, tmp); -- 2.31.1