Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp1635361ybc; Wed, 13 Nov 2019 01:51:02 -0800 (PST) X-Google-Smtp-Source: APXvYqz7/+1G9awNbi5h+pamhwc0JYuENCK8Ys/Ggr5AYIEPxSPMIz2bOE8bM9NppCfPqzvZpTD/ X-Received: by 2002:a17:906:7042:: with SMTP id r2mr1812516ejj.166.1573638662189; Wed, 13 Nov 2019 01:51:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1573638662; cv=none; d=google.com; s=arc-20160816; b=u4GL0vMX5FQzsI1uKHmMbfC0On+ZIeLTwYpEnSwRkQkFUUm1gJyKlb/I9vBI2kok8n WTJT68pAcDWHnRHdDpLz6NdMsCM+VYOGBkCB2saFd0jUBYJFaML9iKdx8sXijiqVOROu iMGqW0amB5HuS/xI/1ZMB3BeE7DUgKj3ylr9XhZvaS/OHde5RKAFXrXqdlAegUlv8Dyr a3Rsyw71H0crgKpDLBw3wxgfidcBEYQlgmvTt7hQaGTa+wIUb0b7xAV9EsxIEWc7cNEE gnVJCFcGtRT6Kb8RA5yUI3EyUiWtXPw3kJe1KDG2ITRUMCVV7pFEaUkFKpUGs5Y5C1FY b9UQ== 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:cc:from:date:content-transfer-encoding:mime-version :subject:to; bh=K/y5AWvEwFBD7UtR45ss07YhnSta9eJzY3aYmT+PI/k=; b=fIs3PSQ4FRvptflHh1/CIxhhOoQ/VZvMtt08JcsqzbrTgbwkISa2rmVFWKBzaOnL+9 5cpZ2yLI7+ecCK4GNAJ8Fel264O811ttQ9jSBwXnOFLjvtipBSF5D3CbgrQp/efVjcWJ kfGpctoue5VDtSNNpW1dykkWSz7DeCEANn1NH5MzV/AwBte0U7Z2j6n83cXKkrHgk/Jv fK8XVUfE/onjJwccjLtHIYBo5L1YWYWmNXz/Zq2TzXEtj1kOP/0yiisUFHGxo2ahB68M kow4ZRM8mRpJP1yhzLK53n+ABKPgoQzKwpFS3ByRF50u66UnJ2BizZUPH9QBYc9ukscK PsSQ== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (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 i13si708969ejj.367.2019.11.13.01.50.37; Wed, 13 Nov 2019 01:51:02 -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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727568AbfKMJrG (ORCPT + 99 others); Wed, 13 Nov 2019 04:47:06 -0500 Received: from inca-roads.misterjones.org ([213.251.177.50]:43814 "EHLO inca-roads.misterjones.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725996AbfKMJrF (ORCPT ); Wed, 13 Nov 2019 04:47:05 -0500 Received: from www-data by cheepnis.misterjones.org with local (Exim 4.80) (envelope-from ) id 1iUpEs-0007KN-22; Wed, 13 Nov 2019 10:47:02 +0100 To: Zenghui Yu Subject: Re: [PATCH v2 12/36] irqchip/gic-v4.1: Implement the v4.1 flavour of VMAPP X-PHP-Originating-Script: 0:main.inc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Date: Wed, 13 Nov 2019 10:56:22 +0109 From: Marc Zyngier Cc: , , Eric Auger , James Morse , Julien Thierry , Suzuki K Poulose , Thomas Gleixner , Jason Cooper , Lorenzo Pieralisi , Andrew Murray , Jayachandran C , Robert Richter , "Wanghaibin (D)" , , In-Reply-To: References: <20191027144234.8395-1-maz@kernel.org> <20191027144234.8395-13-maz@kernel.org> Message-ID: X-Sender: maz@kernel.org User-Agent: Roundcube Webmail/0.7.2 X-SA-Exim-Connect-IP: X-SA-Exim-Rcpt-To: yuzenghui@huawei.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, jnair@marvell.com, rrichter@marvell.com, wanghaibin.wang@huawei.com, jiayanlei@huawei.com, liangboyan@hisilicon.com X-SA-Exim-Mail-From: maz@kernel.org X-SA-Exim-Scanned: No (on cheepnis.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 Hi Zenghui, On 2019-11-13 09:11, Zenghui Yu wrote: > Hi Marc, > > On 2019/10/27 22:42, Marc Zyngier wrote: >> The ITS VMAPP command gains some new fields with GICv4.1: >> - a default doorbell, which allows a single doorbell to be used for >> all the VLPIs routed to a given VPE >> - a pointer to the configuration table (instead of having it in a >> register >> that gets context switched) >> - a flag indicating whether this is the first map or the last unmap >> for >> this particulat VPE >> - a flag indicating whether the pending table is known to be zeroed, >> or not >> Plumb in the new fields in the VMAPP builder, and add the map/unmap >> refcounting so that the ITS can do the right thing. >> Signed-off-by: Marc Zyngier > > [...] > >> @@ -605,19 +626,45 @@ static struct its_vpe >> *its_build_vmapp_cmd(struct its_node *its, >> struct its_cmd_block *cmd, >> struct its_cmd_desc *desc) >> { >> - unsigned long vpt_addr; >> + unsigned long vpt_addr, vconf_addr; >> u64 target; >> - >> - vpt_addr = >> virt_to_phys(page_address(desc->its_vmapp_cmd.vpe->vpt_page)); >> - target = desc->its_vmapp_cmd.col->target_address + >> its->vlpi_redist_offset; >> + bool alloc; >> >> its_encode_cmd(cmd, GITS_CMD_VMAPP); >> its_encode_vpeid(cmd, desc->its_vmapp_cmd.vpe->vpe_id); >> its_encode_valid(cmd, desc->its_vmapp_cmd.valid); >> + >> + if (!desc->its_vmapp_cmd.valid) { >> + if (is_v4_1(its)) { >> + alloc = >> !atomic_dec_return(&desc->its_vmapp_cmd.vpe->vmapp_count); >> + its_encode_alloc(cmd, alloc); >> + } >> + >> + goto out; >> + } >> + >> + vpt_addr = >> virt_to_phys(page_address(desc->its_vmapp_cmd.vpe->vpt_page)); >> + target = desc->its_vmapp_cmd.col->target_address + >> its->vlpi_redist_offset; >> + >> its_encode_target(cmd, target); >> its_encode_vpt_addr(cmd, vpt_addr); >> its_encode_vpt_size(cmd, LPI_NRBITS - 1); >> + if (!is_v4_1(its)) >> + goto out; >> + >> + vconf_addr = >> virt_to_phys(page_address(desc->its_vmapp_cmd.vpe->its_vm->vprop_page)); >> + >> + alloc = >> atomic_inc_and_test(&desc->its_vmapp_cmd.vpe->vmapp_count); > > As the comment block on top of atomic_inc_and_test(atomic *v) says, > > * Atomically increments @v by 1 > * and returns true if the result is zero, or false for all > * other cases. > */ > > We will always get the 'alloc' as false here, even if this is the > first mapping of this vPE. This is not as expected, I think. As usual, a very good observation! Indeed, I cocked up the logic here, as we need to test the value before the increment (and not after). What we want is probably something like: alloc = !atomic_fetch_inc(&desc->its_vmapp_cmd.vpe->vmapp_count); > And on the other hand, I wonder what is the reason for 'vmapp_count' > to be atomic_t? The rational is that we could end-up with multiple VMAPP commands emitted in parallel, for example. That's probably not strictly necessary right now, but I'm trying to be cautious. Thanks, M. -- Jazz is not dead. It just smells funny...