Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp1806634ybl; Thu, 19 Dec 2019 03:21:55 -0800 (PST) X-Google-Smtp-Source: APXvYqxUD9c8dsWet5/OsS9CdDiuoGIXwBRVrSaG0q6XioPOjdO2sLnya66kTvXT3mforhsXGVBN X-Received: by 2002:a05:6830:1608:: with SMTP id g8mr7887499otr.169.1576754515666; Thu, 19 Dec 2019 03:21:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1576754515; cv=none; d=google.com; s=arc-20160816; b=OAUMaCU7TaAjR9v2xCpLB79y28COitf0gN8194EIfDDcupAJm0eztp9DBf3nGApEUj 9uxazX18PV+vJ/ePGyKx9y6I7rutN3upsBpdcGwgji+kf1FXncXmUkcrioSBLKFG8pSr epnxWTFZ3Cu/r2OlrGOYyoIo4AP9fD3BgPZ2sClYPhSM8LNrsOHphSULH1GNhgfpOhc2 8iJFr4JcVANLeaSpm/ZqjDTgwAo79ERWk5UTDsceRLTVGRyeesLEmdEDsupM+nujZ8ui B5bpAGJuIcvsOX+RVDRviHOz83vU1LYJ/rY32FjfGdeGxnVwGhODMvtZ7RVx6cIXd88m bzRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:from:references:cc:to:subject; bh=6DON5tIkMg/tdvV03vSGJZtfYBxSji5mXHU2dIyOna8=; b=uu5EsFRCHE2FqvGUBNcu6iW2UqdGlF0WXlsgziIzJinIhJ5UYhAaZ4V88w/LUgVZ2M NW/TApdgOWUdckj7jCS4pL5cV/yz7oVN6RandN1/4ZArKE1asKzPm0jioy9Cbxc1FNHu /sj06Y84ZAyE3HPGRqGEovhsKMg6TP7c383446rDcTVpKjZZbu5zKvAfU2XfAIWxmUA+ BExIaRdz/4XiXRoyLDOeQHmClyyBSr0TlJMtq+2qTfks/39V/gNz9ccVlc/FiGOtXpcz gzUAaaPAwHqA8CMIWFwHuN66jTgzuKfta2vA+o00QSE8NkIVB6HPsUzZLKPtWVW+IhMG S/MQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b17si1333241otl.320.2019.12.19.03.21.43; Thu, 19 Dec 2019 03:21:55 -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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726836AbfLSLT6 (ORCPT + 99 others); Thu, 19 Dec 2019 06:19:58 -0500 Received: from mx2.suse.de ([195.135.220.15]:40026 "EHLO mx2.suse.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726696AbfLSLT6 (ORCPT ); Thu, 19 Dec 2019 06:19:58 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx2.suse.de (Postfix) with ESMTP id 45C48AB91; Thu, 19 Dec 2019 11:19:56 +0000 (UTC) Subject: Re: [PATCH v2] xen-pciback: optionally allow interrupt enable flag writes To: =?UTF-8?Q?Marek_Marczykowski-G=c3=b3recki?= Cc: xen-devel@lists.xenproject.org, =?UTF-8?Q?Roger_Pau_Monn=c3=a9?= , YueHaibing , Simon Gaiser , Stefano Stabellini , Boris Ostrovsky , Juergen Gross , open list References: <20191219034941.19141-1-marmarek@invisiblethingslab.com> From: Jan Beulich Message-ID: Date: Thu, 19 Dec 2019 12:20:24 +0100 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:60.0) Gecko/20100101 Thunderbird/60.9.1 MIME-Version: 1.0 In-Reply-To: <20191219034941.19141-1-marmarek@invisiblethingslab.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 19.12.2019 04:49, Marek Marczykowski-Górecki wrote: > +enum interrupt_type xen_pcibk_get_interrupt_type(struct pci_dev *dev) > +{ > + int err; > + u16 val; > + > + err = pci_read_config_word(dev, PCI_COMMAND, &val); > + if (err) > + return INTERRUPT_TYPE_ERR; > + if (!(val & PCI_COMMAND_INTX_DISABLE)) > + return INTERRUPT_TYPE_INTX; > + > + /* Do not trust dev->msi(x)_enabled here, as enabling could be done > + * bypassing the pci_*msi* functions, by the qemu. > + */ Judging from this comment, how can you assume only one of the three variants is actually enabled? It's against the spec, yes, but it's not at all impossible afaict. I think you want the return value here to be - negative errno values (no need to discard the actual error codes) or - a non-negative bitmap indicating which of the interrupt types is/are currently enabled. That way ... > +static int msi_msix_flags_write(struct pci_dev *dev, int offset, u16 new_value, > + void *data) > +{ > + int err; > + u16 old_value; > + const struct msi_msix_field_config *field_config = data; > + const struct xen_pcibk_dev_data *dev_data = pci_get_drvdata(dev); > + > + if (xen_pcibk_permissive || dev_data->permissive) > + goto write; > + > + err = pci_read_config_word(dev, offset, &old_value); > + if (err) > + return err; > + > + if (new_value == old_value) > + return 0; > + > + if (!dev_data->allow_interrupt_control || > + (new_value ^ old_value) & ~field_config->enable_bit) > + return PCIBIOS_SET_FAILED; > + > + if (new_value & field_config->enable_bit) { > + /* don't allow enabling together with other interrupt types */ > + const enum interrupt_type int_type = xen_pcibk_get_interrupt_type(dev); > + if (int_type == INTERRUPT_TYPE_NONE || > + int_type == field_config->int_type) ... equality comparisons like this one will actually become safe. Jan