Received: by 2002:ac0:a5a7:0:0:0:0:0 with SMTP id m36-v6csp933271imm; Wed, 11 Jul 2018 13:44:39 -0700 (PDT) X-Google-Smtp-Source: AAOMgpcbpVIlFE7yVN/vc1zcHjtvKgTjljoyqUsgzmBiIxcvJD9hTKpERo2NyaNIKA5vLcuYofW5 X-Received: by 2002:a63:e914:: with SMTP id i20-v6mr174032pgh.10.1531341879859; Wed, 11 Jul 2018 13:44:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531341879; cv=none; d=google.com; s=arc-20160816; b=ZjtwQfTlu9fBFFDyT11Kk1KsKW0bd9Bn1Qz3v6VYTNl86ojwcDapC7PoXBr+OyYFHq poFMGNl7hSabScz2IEL54C1LBZnK8Cn/rrqn8YUd3lmcMmesekRM3rqIH6+NhK/WwfW4 mTxVtitYj/sazh2Tupe9P8hoomeUahjSq4NBAgyQoOP5TlgCEFP0Q67ULYAYGa7amLS5 5i+TtZ2Y08jolk7X8KrgJvl1K8rlZP90D/7cJzrp03DQ6SwT7lCt5wK0VX/z3zmFZmSs RD2aARgDcNcTyNfO/cudxkKCVOOEGEFiVUYyaxFeXGeZMJIRK4LSiUlKKZt+ZM09pvSb HNkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature:arc-authentication-results; bh=Y6u97+/sQjuzhzy5/ZkJdItnZDX3We5CPROIWF5G+dw=; b=z5OUX25mk+FUoHjKRqydC7X6ivwlmlL13kbQBVDtaA0gMBpOaEm3G6R2mKtuMuOHHR 6rVpq9jLuQ8/pKrEmd3sBHuAbqWOFUZGGEPnPlvqc8IgHMKVUYf/sLwSDr+iGevN3NWH DaLHj3mWYRMoBKSR6Eg1tgB23+BmWQA9C69UphM//Odj5u4KYs1y1erWmgwqLMo3pZGB Ezu/M2+/yrTUP9Bnl7RFMa87OSPclY9wM3OpNIBwuqQmBC+ZcAjrAl0u5CCbWT0pV8M3 5iMGu6vzrk97g53jLPW+BXdziU7ZOGKD4C1pQeGl+9ilD1+Gbgi2LouYZOfYflbT+OzC rLWw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=uTXRxoxD; 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 f14-v6si18964064pgr.290.2018.07.11.13.44.24; Wed, 11 Jul 2018 13:44:39 -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=fail header.i=@infradead.org header.s=bombadil.20170209 header.b=uTXRxoxD; 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 S2387982AbeGKOTN (ORCPT + 99 others); Wed, 11 Jul 2018 10:19:13 -0400 Received: from bombadil.infradead.org ([198.137.202.133]:50108 "EHLO bombadil.infradead.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726639AbeGKOTN (ORCPT ); Wed, 11 Jul 2018 10:19:13 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20170209; h=In-Reply-To:Content-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=Y6u97+/sQjuzhzy5/ZkJdItnZDX3We5CPROIWF5G+dw=; b=uTXRxoxD2Fr5dx9hRUxBZBFOH hdWAAQhKN3ooTXkreIf09+up/49+FpA9cNO6SMh+7S80QfRNKzAte20UqllkqUWovTZEHykxpi4Z6 gQXwX7/108LglGlBDn7ley0oSt4jhlfVSK4/B3kB9MXvJ+BciIwWxzeNpxGJOHA4XFZswfWg86zoC rBqAn9lCN7STVxQYn/drTCOHvr5YJpE9M+Gk4rnn38i01jBw9Ycwv4ogrsP/rDzHeEFXhfL/6OnUX Cy0WtVnNWWGJKmIm8A5Y6Yi/NzqIx+jXXgMtdi5r4ari78VLg6xHhbgUiGL6/SALwRBmA8tTZR2Ot GvRkpV8EQ==; Received: from willy by bombadil.infradead.org with local (Exim 4.90_1 #2 (Red Hat Linux)) id 1fdFs2-0006kV-BC; Wed, 11 Jul 2018 14:14:21 +0000 Date: Wed, 11 Jul 2018 07:13:29 -0700 From: Matthew Wilcox To: Dominique Martinet Cc: v9fs-developer@lists.sourceforge.net, Latchesar Ionkov , Eric Van Hensbergen , linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org, Ron Minnich Subject: Re: [V9fs-developer] [PATCH 5/6] 9p: Use a slab for allocating requests Message-ID: <20180711141256.GC23640@bombadil.infradead.org> References: <20180628132629.3148-1-willy@infradead.org> <20180628132629.3148-6-willy@infradead.org> <20180711133313.GC835@nautica> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20180711133313.GC835@nautica> User-Agent: Mutt/1.9.2 (2017-12-15) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Jul 11, 2018 at 03:33:13PM +0200, Dominique Martinet wrote: > Matthew Wilcox wrote on Thu, Jun 28, 2018: > > /** > > * struct p9_client - per client instance state > > - * @lock: protect @fidlist > > + * @lock: protect @fids and @reqs > > * @msize: maximum data size negotiated by protocol > > - * @dotu: extension flags negotiated by protocol > > * @proto_version: 9P protocol version to use > > * @trans_mod: module API instantiated with this client > > + * @status: XXX > > Let's give this a proper comment; something like 'connection state > machine' ? (this contains Connected/BeginDisconnect/Disconnected/Hung) Sure! Will add. > > /** > > - * p9_tag_alloc - lookup/allocate a request by tag > > - * @c: client session to lookup tag within > > - * @tag: numeric id for transaction > > - * > > - * this is a simple array lookup, but will grow the > > - * request_slots as necessary to accommodate transaction > > - * ids which did not previously have a slot. > > - * > > - * this code relies on the client spinlock to manage locks, its > > - * possible we should switch to something else, but I'd rather > > - * stick with something low-overhead for the common case. > > + * p9_req_alloc - Allocate a new request. > > + * @c: Client session. > > + * @type: Transaction type. > > + * @max_size: Maximum packet size for this request. > > * > > + * Context: Process context. What mutex might we be holding that > > + * requires GFP_NOFS? > > Good question, but p9_tag_alloc happens on every single client request > so the fs/9p functions might be trying to do something and the alloc > request here comes in and could try to destroy the inode that is > currently used in the request -- I'm not sure how likely this is, but > I'd rather not tempt fate :p Fair. I'll remove the question. > > + INIT_LIST_HEAD(&req->req_list); > > + > > + idr_preload(GFP_NOFS); > > + spin_lock_irq(&c->lock); > > + if (type == P9_TVERSION) > > + tag = idr_alloc(&c->reqs, req, P9_NOTAG, P9_NOTAG + 1, > > + GFP_NOWAIT); > > Well this appears to work but P9_NOTAG being '(u16)(~0)' I'm not too > confident with P9_NOTAG + 1. . . it doesn't look like it's overflowing > before the cast on my laptop but is that guaranteed? By my understanding of n1256.pdf ... this falls under 6.3.1.8 ("Usual arithmetic conversions"). We have a u16 and an int. Therefore this rule applies: Otherwise, if the type of the operand with signed integer type can represent all of the values of the type of the operand with unsigned integer type, then the operand with unsigned integer type is converted to the type of the operand with signed integer type. > > [..] > > @@ -1012,14 +940,11 @@ struct p9_client *p9_client_create(const char *dev_name, char *options) > > > > spin_lock_init(&clnt->lock); > > idr_init(&clnt->fids); > > - > > - err = p9_tag_init(clnt); > > - if (err < 0) > > - goto free_client; > > + idr_init(&clnt->reqs); > > I do not see any call to idr_destroy, is that OK? Yes, that's fine. It used to be (back in 2013) that one had to call idr_destroy() in order to free the preallocated idr data structures. Now it's a no-op if called on an empty IDR, and I would expect that both IDRs are empty at the time that it comes to unloading the module (and if they aren't, we probably have bigger problems than a small memory leak). Some users like to assert that the IDR is empty; most do not go to that extent of defensive programming.