Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp6472486ybl; Wed, 15 Jan 2020 05:19:04 -0800 (PST) X-Google-Smtp-Source: APXvYqwLj0wh6JjhyJgSAyRePoDdQQ0TIq+OBc86q34PgPBXPd+fAyXqgFJY+HfAqGFvA2E0PaGK X-Received: by 2002:a9d:4c94:: with SMTP id m20mr2736933otf.341.1579094344461; Wed, 15 Jan 2020 05:19:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1579094344; cv=none; d=google.com; s=arc-20160816; b=M8x+67UqPWdsTXRGEMrsLD+19uiFNu0bwC5rbQA2Gn9vuEHfHeCrtJpdroq7bl5Cnb VT6Bsh+fZfW/8B1mCKB2CIzEloPCDsNJlp2ie+00YHR8qq/ntoXVggv9IweCKAy+AjIb d7OfxNTkf9eV37STEI9x3A5GF6b1OuxS5EZgP6Cc/R/CNc1SzUvlnikREWuz2x/PPvHx KL64c5HKAwpYsypHqYdapiPzPp01sT/GArpI7zBAf3PrQpH7b8UXjtKyX4oOaOi2pDI6 JPehIELG6Lj9Wox1XOQKfduUs0oHNg4qvj/SEUxPxF4hb/xi1Wpsav5JLkvzAiKJ6CnP cFDA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:message-id:references :in-reply-to:subject:cc:to:from:date:content-transfer-encoding :mime-version:dkim-signature; bh=wwzGVfcZYIzIqUxOXLofCiXPNiJZT6dD46Cxh1E+OrM=; b=vfoWMeaXj4CHqdi3Exvh0Dl5QjCFan53ZlxigtTzBo/1tbdh5ACCZzeUb3h40xnH1v Js9pg8Zqe4JMlouIl1O3+ZIHDUtlyWe6zBlsdkJpry4W774GjSLaWQzpygPwrRa0JbDQ VIJ66ZAvQcItgjK4gj3lr9Z+6/j3L2hBezUxpuBdREX3UaOLEQASBMbb7Trs4aBZGsRI uB6SXKOCKYNxwcI1NKRvmfEeLI2/dJo1+ZQ2co1box9T4zM/cC8BlDPeoHk8UOeXFV2n bQ61nIIaM8rrp4LHkpIckPoFXWoD1QZqZc+H5/XffcFc7++Mj6WFjAJ2Jq0w+HoUN7KL IthQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P3hHTqIJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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. [209.132.180.67]) by mx.google.com with ESMTP id a3si10473697otr.37.2020.01.15.05.18.50; Wed, 15 Jan 2020 05:19:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=P3hHTqIJ; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 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 S1729043AbgAONR2 (ORCPT + 99 others); Wed, 15 Jan 2020 08:17:28 -0500 Received: from mail.kernel.org ([198.145.29.99]:58176 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728931AbgAONR2 (ORCPT ); Wed, 15 Jan 2020 08:17:28 -0500 Received: from disco-boy.misterjones.org (disco-boy.misterjones.org [51.254.78.96]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 834FE2084D; Wed, 15 Jan 2020 13:17:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1579094246; bh=//qznMGw/pxNvBtv/o96KOZTY0ZVAWOVKTbjHmr/Db0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=P3hHTqIJ1elb0u7PAj2RTmURQSF5yBhKJH2rJSYUWFly+B5C1JAE+hjfPFKncEQxW DSSYZU0kFnfuYffG8kQqiPuk8vr649ADwIAf0CYgEeCQRGr9xMrX1upp20E5u4RE2P n7FpV4LopngSFeOfLUjNCGNPIfgSU+FXjcSQCEA0= Received: from disco-boy.misterjones.org ([51.254.78.96] helo=www.loen.fr) by disco-boy.misterjones.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1iriY0-00085i-AJ; Wed, 15 Jan 2020 13:17:24 +0000 MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 15 Jan 2020 13:17:24 +0000 From: Marc Zyngier To: Shaokun Zhang Cc: kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, Eric Auger , James Morse , Julien Thierry , Suzuki K Poulose , Thomas Gleixner , Jason Cooper , Lorenzo Pieralisi , Andrew Murray , Zenghui Yu , Robert Richter , "Tangnianyao (ICT)" Subject: Re: [PATCH v3 29/32] KVM: arm64: GICv4.1: Allow SGIs to switch between HW and SW interrupts In-Reply-To: References: <20191224111055.11836-1-maz@kernel.org> <20191224111055.11836-30-maz@kernel.org> Message-ID: X-Sender: maz@kernel.org User-Agent: Roundcube Webmail/1.3.8 X-SA-Exim-Connect-IP: 51.254.78.96 X-SA-Exim-Rcpt-To: zhangshaokun@hisilicon.com, kvmarm@lists.cs.columbia.edu, linux-kernel@vger.kernel.org, eric.auger@redhat.com, james.morse@arm.com, julien.thierry.kdev@gmail.com, suzuki.poulose@arm.com, tglx@linutronix.de, jason@lakedaemon.net, lorenzo.pieralisi@arm.com, Andrew.Murray@arm.com, yuzenghui@huawei.com, rrichter@marvell.com, tangnianyao@huawei.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on disco-boy.misterjones.org); SAEximRunCond expanded to false Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 2020-01-15 02:49, Shaokun Zhang wrote: > Hi Marc, [This is from Nianyao] > > On 2019/12/24 19:10, Marc Zyngier wrote: >> In order to let a guest buy in the new, active-less SGIs, we >> need to be able to switch between the two modes. >> >> Handle this by stopping all guest activity, transfer the state >> from one mode to the other, and resume the guest. >> >> Signed-off-by: Marc Zyngier >> --- >> include/kvm/arm_vgic.h | 3 ++ >> virt/kvm/arm/vgic/vgic-v3.c | 2 + >> virt/kvm/arm/vgic/vgic-v4.c | 96 >> +++++++++++++++++++++++++++++++++++++ >> virt/kvm/arm/vgic/vgic.h | 1 + >> 4 files changed, 102 insertions(+) >> >> diff --git a/include/kvm/arm_vgic.h b/include/kvm/arm_vgic.h >> index 63457908c9c4..69f4164d6477 100644 >> --- a/include/kvm/arm_vgic.h >> +++ b/include/kvm/arm_vgic.h >> @@ -231,6 +231,9 @@ struct vgic_dist { >> /* distributor enabled */ >> bool enabled; >> >> + /* Wants SGIs without active state */ >> + bool nassgireq; >> + >> struct vgic_irq *spis; >> >> struct vgic_io_device dist_iodev; >> diff --git a/virt/kvm/arm/vgic/vgic-v3.c b/virt/kvm/arm/vgic/vgic-v3.c >> index c2fdea201747..c79a251c4974 100644 >> --- a/virt/kvm/arm/vgic/vgic-v3.c >> +++ b/virt/kvm/arm/vgic/vgic-v3.c >> @@ -540,6 +540,8 @@ int vgic_v3_map_resources(struct kvm *kvm) >> goto out; >> } >> >> + if (kvm_vgic_global_state.has_gicv4_1) >> + vgic_v4_configure_vsgis(kvm); >> dist->ready = true; >> >> out: >> diff --git a/virt/kvm/arm/vgic/vgic-v4.c b/virt/kvm/arm/vgic/vgic-v4.c >> index c2fcde104ea2..063785fd2dc7 100644 >> --- a/virt/kvm/arm/vgic/vgic-v4.c >> +++ b/virt/kvm/arm/vgic/vgic-v4.c >> @@ -97,6 +97,102 @@ static irqreturn_t vgic_v4_doorbell_handler(int >> irq, void *info) >> return IRQ_HANDLED; >> } >> >> +static void vgic_v4_sync_sgi_config(struct its_vpe *vpe, struct >> vgic_irq *irq) >> +{ >> + vpe->sgi_config[irq->intid].enabled = irq->enabled; >> + vpe->sgi_config[irq->intid].group = irq->group; >> + vpe->sgi_config[irq->intid].priority = irq->priority; >> +} >> + >> +static void vgic_v4_enable_vsgis(struct kvm_vcpu *vcpu) >> +{ >> + struct its_vpe *vpe = &vcpu->arch.vgic_cpu.vgic_v3.its_vpe; >> + int i; >> + >> + /* >> + * With GICv4.1, every virtual SGI can be directly injected. So >> + * let's pretend that they are HW interrupts, tied to a host >> + * IRQ. The SGI code will do its magic. >> + */ >> + for (i = 0; i < VGIC_NR_SGIS; i++) { >> + struct vgic_irq *irq = vgic_get_irq(vcpu->kvm, vcpu, i); >> + struct irq_desc *desc; >> + int ret; >> + >> + if (irq->hw) { >> + vgic_put_irq(vcpu->kvm, irq); >> + continue; >> + } >> + >> + irq->hw = true; >> + irq->host_irq = irq_find_mapping(vpe->sgi_domain, i); > > I think we need to check whether irq_find_mapping returns 0. Why? its_alloc_vcpu_sgis() performs the allocation of all 16 SGIs in one go. If that fails, we should error out. Conversely, we're guaranteed that we have a mapping if it hasn't failed. > >> + vgic_v4_sync_sgi_config(vpe, irq); >> + /* >> + * SGIs are initialised as disabled. Enable them if >> + * required by the rest of the VGIC init code. >> + */ >> + desc = irq_to_desc(irq->host_irq); >> + ret = irq_domain_activate_irq(irq_desc_get_irq_data(desc), >> + false); > > If irq->host_irq is not valid , in irq_domain_activate_irq, it will > trigger NULL pointer dereference in host kernel. > I meet a problem here. When hw support GIC4.1, and host kernel is > started with > kvm-arm.vgic_v4_enable=0, starting a virtual machine will trigger NULL > pointer > dereference in host. The following is error info: [...] But the problem here is that we're trying to use GICv4.1 even if GICv4 is disabled. I don't think there is a point in trying to sidestep this locally if we're doing the wrong thing at top-level, which seems to be the case. Thanks, M. -- Jazz is not dead. It just smells funny...