Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3666622ybb; Mon, 23 Mar 2020 05:31:33 -0700 (PDT) X-Google-Smtp-Source: ADFU+vss6SO2Mc5s+Tx2r3KUFPYfYp999590TrFpiWVNuPApOOQm4cCh4NTxelmrikMmteIj/4FX X-Received: by 2002:aca:c209:: with SMTP id s9mr2280208oif.131.1584966693577; Mon, 23 Mar 2020 05:31:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1584966693; cv=pass; d=google.com; s=arc-20160816; b=uzJgbFOE+Uvq5B+5q4gcq7bTD9kTgjzOlVLGpYOp9TYKIf+J9CAZfDqpOwsDsYbhLY zoOBxaVm4ixPwOiu2v1d2iUMyPql8e3OAifw7EAAE18Hd7z+B44HlTc9urfIQYQXZZAU AIxNsNsKW+WPbEKxDWuuCCY48V+4QygmwB0hlDzjhCORriEC9lRCiTkBP4JuQno5Qkty jCyiCnLtGXyyQuzS//xPe1vtjDAgrFa9UCQNdIwg9BrIZrqP9Du8xm3VgwgjW/tTlDpY ZEEFaGcGryn0l74fCCCrV2wztNN2hK1lHAAUdKOkRIbgF5umOJCnviq33S31pHe8ghCz 0J2Q== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :content-language:in-reply-to:user-agent:date:message-id:from :references:cc:to:subject:dkim-signature; bh=5so9viG1dd8HI/hADL7eqqQfiAxBST22N/GIJ+2T2Ds=; b=cZUMQLHiYKHUPSLbCoxxE1MVKa/7zGD2NWqVNYSvWVrQjF9axSMuFF3ZwrEyFEhx3g eONIkBwxRfHxldxWOb+t6LPOq0CftO2GQc7SPYkHLcR0MzP+Cm8K2GXcmpN+kbuK6iwr skIM9PqOmSX9Y/OcZz1PrIu5oLR2Bov+A1svfOgYlR1Od1hyeWyyAZlfIyaR7v0Cr58t ArXY9DSCj2gMJXW9yHmhsQ8TwuTwKRtIcoNVOqzSF17UVWs8IGIT/0JK8fvRHmcQNJIw X7qg0GxE8c5lHwI2rSAcpor00taNUTzIaC9hns9IVGtDV8Vx3qOhpkc6/ZU82LGbk1rh I67g== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@nxp.com header.s=selector2 header.b=VVht3xDQ; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.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=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l21si7584213otq.144.2020.03.23.05.31.19; Mon, 23 Mar 2020 05:31:33 -0700 (PDT) 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=@nxp.com header.s=selector2 header.b=VVht3xDQ; arc=pass (i=1 spf=pass spfdomain=nxp.com dkim=pass dkdomain=nxp.com dmarc=pass fromdomain=nxp.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=pass (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727864AbgCWMbB (ORCPT + 99 others); Mon, 23 Mar 2020 08:31:01 -0400 Received: from mail-eopbgr30040.outbound.protection.outlook.com ([40.107.3.40]:22177 "EHLO EUR03-AM5-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727457AbgCWMbA (ORCPT ); Mon, 23 Mar 2020 08:31:00 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=AkQwYLKjRtUudNx7vmJG2h2w8FQ/AfF1Q1PjCx0/piB60146DkePsm2flb5GFDcHo0QDFSuNnIwQAjawvhU8pRtIYJHoz0uTQf6DTTc2q4hvzugWlWdG66dMiiT6P9RppfTlwbrIzrEqNLex7tdKKEtTbMPuM6Qtg3w6qx6+MFSz/+WhUwE2ZoBxfU54Z1K2ZykRXyVgOwfTWjtJFpZ7SWzKrSbnMo4Ycbll0SBRDU2xqicTBG/WxGOqqiHPVVzzU4YLeHoMnw9ZLxaLmpgVguSk/vLlmDDM9XeqPPeitPS7qkwwfOrHys0n5lbgx+aT/MejtglSbTYlOCYgBAnCdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5so9viG1dd8HI/hADL7eqqQfiAxBST22N/GIJ+2T2Ds=; b=AxexCIsk7boQPkZFKGlfpJ96J1rVxXL0x3qIjYQdD7i5Osx3gCZtX7PMjnHXKT7mqTi1wGTNskgFGM/NgoKKPzu2jkIdqnws7XrAJ90quN+ttuG9wdd8APtJSSEFDm2xaoceZsfe5BdOCxgZHNl5A534l+iAnYXwoeboUzhARyXqi5ZYp7HZU6kCrjkMc/6g2qwePlkDxldZuVG6z2Ph1U0pS4+1JpGQzbsY6fV+o2FBUIcgjWHCeQdis5+kCkJwm07hHHMoeeUo+qrRhcpKtPrfd1/hWHkS8WHlGxqcFBKFgTfRfVYylenPMIkHzVjrPqaPRX0FqDyOxr5ga/woxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=5so9viG1dd8HI/hADL7eqqQfiAxBST22N/GIJ+2T2Ds=; b=VVht3xDQ0PRYH6ldsJzGbQ4+5/ZTRVQ6zekTrQEFYC+bX6T++ZJRSU8dhtIHdco5qtEl46JkrdQc0bDPAdoGKYkkF7uI+kzem20zk2niXfo+4ykbQhz5SDct17IilecPMtxZ4AfSjOjifJXYMzWt2U+kT437NN1h/iFSR/i7TMI= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=laurentiu.tudor@nxp.com; Received: from AM6PR04MB5925.eurprd04.prod.outlook.com (20.179.2.147) by AM6PR04MB4280.eurprd04.prod.outlook.com (52.135.162.31) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.20; Mon, 23 Mar 2020 12:30:56 +0000 Received: from AM6PR04MB5925.eurprd04.prod.outlook.com ([fe80::dd71:5f33:1b21:cd9e]) by AM6PR04MB5925.eurprd04.prod.outlook.com ([fe80::dd71:5f33:1b21:cd9e%5]) with mapi id 15.20.2835.021; Mon, 23 Mar 2020 12:30:56 +0000 Subject: Re: [PATCH 03/10] bus/fsl-mc: add support for 'driver_override' in the mc-bus To: Diana Craciun , linux-kernel@vger.kernel.org, stuyoder@gmail.com, leoyang.li@nxp.com, linux-arm-kernel@lists.infradead.org, bharatb.yadav@gmail.com Cc: Bharat Bhushan References: <20200319154051.30609-1-diana.craciun@oss.nxp.com> <20200319154051.30609-4-diana.craciun@oss.nxp.com> From: Laurentiu Tudor Message-ID: <99ef2746-6be8-5427-26af-0a34c17f8fd2@nxp.com> Date: Mon, 23 Mar 2020 14:30:44 +0200 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.6.0 In-Reply-To: <20200319154051.30609-4-diana.craciun@oss.nxp.com> Content-Type: text/plain; charset=utf-8 Content-Language: en-GB Content-Transfer-Encoding: 7bit X-ClientProxiedBy: BY5PR03CA0028.namprd03.prod.outlook.com (2603:10b6:a03:1e0::38) To AM6PR04MB5925.eurprd04.prod.outlook.com (2603:10a6:20b:ab::19) MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [10.213.175.155] (192.88.158.246) by BY5PR03CA0028.namprd03.prod.outlook.com (2603:10b6:a03:1e0::38) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2835.20 via Frontend Transport; Mon, 23 Mar 2020 12:30:52 +0000 X-Originating-IP: [192.88.158.246] X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-MS-Office365-Filtering-Correlation-Id: 97ddb2cb-47fe-4f04-3bbf-08d7cf260892 X-MS-TrafficTypeDiagnostic: AM6PR04MB4280:|AM6PR04MB4280: X-MS-Exchange-Transport-Forked: True X-Microsoft-Antispam-PRVS: X-MS-Oob-TLC-OOBClassifiers: OLM:7219; X-Forefront-PRVS: 0351D213B3 X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(4636009)(39860400002)(366004)(346002)(376002)(136003)(396003)(199004)(36756003)(186003)(4326008)(16526019)(5660300002)(316002)(16576012)(31686004)(2906002)(66476007)(44832011)(6666004)(66556008)(53546011)(6486002)(86362001)(26005)(52116002)(2616005)(956004)(478600001)(31696002)(8676002)(81166006)(81156014)(66946007)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:AM6PR04MB4280;H:AM6PR04MB5925.eurprd04.prod.outlook.com;FPR:;SPF:None;LANG:en;PTR:InfoNoRecords;A:1; Received-SPF: None (protection.outlook.com: nxp.com does not designate permitted sender hosts) X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qGvRSmDlL3yAMjMthxoHNh3NLzNZJR/YHDCEXSwHjHUU/rTl20tJwGNO37TGgjMGyfSF7wvSWdEh3XhcDHxn8LhENXY1GBHzbVJsB1ZlNKJFk1F0mWGf6DSvRPlONwFMzSWqb621Us1FQSOBkquUo2EtNoampe0rggL9qwQI/wpSUc4vG12N+zsMQDQc9qItosu7RR0pQ4iYmV/7RjnNhBpRgFmabAflBlLvqMJzt2zXTaqYhYzUeCpnqLoTVipq7fO4rGtPWyLcXSoCDI3St0IoBymzrcF5risxznTps71Zy6ieC78zKp8TviIB0DMa73+GcIhexvkBxEyPP1o26y4M5rR9b34rdGd33vl9kQ9x6RH4J5SE4MH5eeJtz9fF5WSsfXcoL3+hgq4V3oPrJSDYAqI4VMdMmlE8um1FPALXWRDzbTZWg6qsUYSuf6oe X-MS-Exchange-AntiSpam-MessageData: bwn0Q8ezTbWLQH0xF9xaXR6THiG0pToFENrhsiEx1CAg7O2oCup6LDk96lFbuOPVJ/HpfnmVr0s+tQpPRK+0tZhzdwNvliidZQ3pC3XjEsNAn+h1sQju/QeyYAHSI2uVBJGmKLZFhsvii4YDaLOI3w== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 97ddb2cb-47fe-4f04-3bbf-08d7cf260892 X-MS-Exchange-CrossTenant-OriginalArrivalTime: 23 Mar 2020 12:30:55.8491 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: INVMLx/O81ypnF8knnoA6QdBXGp1WphXsfUMMRhmsC5FA69OXcXM2qlcv3KcD/lglF9Vd9GHHflDU72wQBNC+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AM6PR04MB4280 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 3/19/2020 5:40 PM, Diana Craciun wrote: > From: Bharat Bhushan > > This patch is required for vfio-fsl-mc meta driver to successfully bind > layerscape container devices for device passthrough. This patch adds > a mechanism to allow a layerscape device to specify a driver rather than > a layerscape driver provide a device match. > > Example to allow a device (dprc.1) to specifically bind > with driver (vfio-fsl-mc):- > - echo vfio-fsl-mc > /sys/bus/fsl-mc/devices/dprc.1/driver_override > - echo dprc.1 > /sys/bus/fsl-mc/drivers/fsl_mc_dprc/unbind > - echo dprc.1 > /sys/bus/fsl-mc/drivers/vfio-fsl-mc/bind > > Signed-off-by: Bharat Bhushan > Signed-off-by: Laurentiu Tudor > Signed-off-by: Diana Craciun > --- > drivers/bus/fsl-mc/fsl-mc-bus.c | 54 +++++++++++++++++++++++++++++++++ > include/linux/fsl/mc.h | 1 + > 2 files changed, 55 insertions(+) > > diff --git a/drivers/bus/fsl-mc/fsl-mc-bus.c b/drivers/bus/fsl-mc/fsl-mc-bus.c > index c78d10ea641f..baf8259262a9 100644 > --- a/drivers/bus/fsl-mc/fsl-mc-bus.c > +++ b/drivers/bus/fsl-mc/fsl-mc-bus.c > @@ -3,6 +3,7 @@ > * Freescale Management Complex (MC) bus driver > * > * Copyright (C) 2014-2016 Freescale Semiconductor, Inc. > + * Copyright 2019-2020 NXP > * Author: German Rivera > * > */ > @@ -83,6 +84,12 @@ static int fsl_mc_bus_match(struct device *dev, struct device_driver *drv) > struct fsl_mc_driver *mc_drv = to_fsl_mc_driver(drv); > bool found = false; > > + /* When driver_override is set, only bind to the matching driver */ > + if (mc_dev->driver_override) { > + found = !strcmp(mc_dev->driver_override, mc_drv->driver.name); I think we can use sysfs_streq() here and ... > + goto out; > + } > + > if (!mc_drv->match_id_table) > goto out; > > @@ -147,8 +154,52 @@ static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, > } > static DEVICE_ATTR_RO(modalias); > > +static ssize_t driver_override_store(struct device *dev, > + struct device_attribute *attr, > + const char *buf, size_t count) > +{ > + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); > + const char *driver_override, *old = mc_dev->driver_override; > + char *cp; > + > + if (WARN_ON(dev->bus != &fsl_mc_bus_type)) > + return -EINVAL; > + > + if (count >= (PAGE_SIZE - 1)) > + return -EINVAL; > + > + driver_override = kstrndup(buf, count, GFP_KERNEL); > + if (!driver_override) > + return -ENOMEM; > + > + cp = strchr(driver_override, '\n'); > + if (cp) > + *cp = '\0'; drop this strchr() ... > + if (strlen(driver_override)) { > + mc_dev->driver_override = driver_override; > + } else { > + kfree(driver_override); > + mc_dev->driver_override = NULL; > + } > + > + kfree(old); > + > + return count; > +} > + > +static ssize_t driver_override_show(struct device *dev, > + struct device_attribute *attr, char *buf) > +{ > + struct fsl_mc_device *mc_dev = to_fsl_mc_device(dev); > + > + return snprintf(buf, PAGE_SIZE, "%s\n", mc_dev->driver_override); and also the terminating '\n' here. > +} > +static DEVICE_ATTR_RW(driver_override); > + > static struct attribute *fsl_mc_dev_attrs[] = { > &dev_attr_modalias.attr, > + &dev_attr_driver_override.attr, > NULL, > }; > > @@ -704,6 +755,9 @@ EXPORT_SYMBOL_GPL(fsl_mc_device_add); > */ > void fsl_mc_device_remove(struct fsl_mc_device *mc_dev) > { > + kfree(mc_dev->driver_override); > + mc_dev->driver_override = NULL; > + > /* > * The device-specific remove callback will get invoked by device_del() > */ > diff --git a/include/linux/fsl/mc.h b/include/linux/fsl/mc.h > index 54d9436600c7..88095fd30c80 100644 > --- a/include/linux/fsl/mc.h > +++ b/include/linux/fsl/mc.h > @@ -194,6 +194,7 @@ struct fsl_mc_device { > struct fsl_mc_device_irq **irqs; > struct fsl_mc_resource *resource; > struct device_link *consumer_link; > + const char *driver_override; We probably don't want const here. --- Best Regards, Laurentiu > }; > > #define to_fsl_mc_device(_dev) \ >