From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-ej1-f54.google.com (mail-ej1-f54.google.com [209.85.218.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AAFC2339379 for ; Wed, 22 Jul 2026 10:23:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784715838; cv=none; b=o4AdredTtgprdMuymepy4RHSrDtr/iGsd0Mk9Zkc+fu2wCAJhSUgGbDUSf68xniNF4vH6OuaUkvSr0m1sOznLi4Mif5uDt5JjRjftEmu1adVjbbTANIMAUY6y/6huHZr9NWNv++rrYPYCyvWW/FJe7+a27DwZuPWczYYyFluOaE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784715838; c=relaxed/simple; bh=H7Nca37WRkQauVBsrDNcHqeWLZsewmKW59qsuV9SkhM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=nO+2sDygmAlB8lt4I+3oTKOEYtjZtcWwNoHgnanfE2bQR4EpqiRLXuXBK6Lxs/2bXmXJ+mPRVlFZ3sBjDwViQNVIafsGxj0k1XEVRfpdFgt7xk0uj9lvq+6aDwQMa59g/qOogqGrkW1KChffeOQSrFf67qA4Ze3RQwQnN5g1FsI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=sumYmjsa; arc=none smtp.client-ip=209.85.218.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="sumYmjsa" Received: by mail-ej1-f54.google.com with SMTP id a640c23a62f3a-c167aa9500dso997806366b.3 for ; Wed, 22 Jul 2026 03:23:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1784715834; x=1785320634; darn=vger.kernel.org; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to:content-type; bh=toUhRicgKnyayDX2ZRlKZA5Y5hvlvcz+H/bR233rzCg=; b=sumYmjsaAwyW4yMnLGDOuUnxBaAVY/FOPtDGk5Elhe3AOOq9RQlKxwCS3HXw2zhS6A 0on3mqGnI5Akv3aRjdZtJhFxZHEVWqoDWXann2tF8wldZZmH4wXYOHlELp5YuU2Ooa0J PK2wAgPsaOZp9Um7mqWjWQ7tmBNRw17gqzvoHFCrUojtLiKzgmsDP28Nf8C1VW06u6j9 AEP6aGemiuESQOD06N1urtp6APZ9AayAvDylG7nNRngU4aZaMV+NR4gAt/c3kDvZ8URy 2NB6O1kxZ5L5x+MerBn5dTLqZN2ncQHNJgNfsRmq5QAxa7EkhM6A7DTJPFSJJPGfqa5l wnbA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784715834; x=1785320634; h=references:in-reply-to:message-id:date:subject:cc:to:from:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=toUhRicgKnyayDX2ZRlKZA5Y5hvlvcz+H/bR233rzCg=; b=eT9mNCjCXDb1vGRBMENSTWzCh8/bu3RBwF0CBND9EJoHJTIB2OrwM6jxUcD52nWrwj Vvxrw4vC91S2Tvh6HZMG/o5tjkEB13yQd5gL/wr7w1MyWHn5AEemIOLSUFbn6620930q PBMQU+M6v+yODe6XVWfx0Y36xhhXjShQi35wu3v15ppQ8s6BLps8nuqi5t5KkqycC9Us jPvgZ3O67BjsG+lA7E8fn7RjGgNYCZ52ZRW3mPrN483IzDHs6T4pI6EHiwyNzH2rByR1 9Jwq0mFn39Fd7JuFicnPWoTTuvAoVuEeO4hin3lzccrN6iPEY9ufZd5ER+UnlY37Zs8m Fc4w== X-Forwarded-Encrypted: i=1; AHgh+RpOG0UyEftY0a6C2IL9gVds84v9bYdLRFRDZi6pewg1kyOvW5RtGIThEKXHaMuhaR4Hxx+A9FB5tL2veo0=@vger.kernel.org X-Gm-Message-State: AOJu0YzcPGc7HkmoID672UKxowf/eeRD04ihP6dE7RUYO+bNJFheSMmL t7MWHGhYtI+8iChk3g+XRnOw+HV7NA8+AZ3Itd0fQUJmRVSVcTsyWZFxPefjiw== X-Gm-Gg: AR+sD12fEjrA8FXK8PmSYKObNTlCx5hUoWxtntIg0mPjONDNgf/HTK7AlJ03+VvYkpa V391xWczhGQKYsB2Ja7ZUd0KmXP7+lcdrIx12OrLYJNSK35Vdtu1HN2bfVqQU4KMBX71c8uF2mG c0gaBadbO1b1+mfw8NcuOp2ljcE/CN+W2eN+lYFjwRH0/hPAnBbcKCPUNos6DwoZw/Zh762BAiK kCiebx4lihVnI6HM0XSMCwzK8qtAu9mdR3a7rviNkAja5HRPx8tWrAgR99M+UX8QbwB5QA+CbHW QeUueo3LcQiQ4KjkDLNo0HBSQoeA3jW9pQqUrqgmYzkqV3sK3FkIBA98tNsNRIyrECy/ukTbNqO e5ou0HOC2DB39EFt1QDuY5g9lbMO5gsxnJEGhl9OUD/o7z4+VmcdGZCosCsc1AXf9scuepvKEbQ pxmf88SkYdCeTWrYXOVu8oBlUZzAkOkgIZSi3jF+Ku X-Received: by 2002:a17:907:e84a:b0:c16:e3b:7d6 with SMTP id a640c23a62f3a-c16b4807dfbmr929383566b.54.1784715834341; Wed, 22 Jul 2026 03:23:54 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-c1c32c8ea94sm82894266b.41.2026.07.22.03.23.53 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Wed, 22 Jul 2026 03:23:53 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, Eli Billauer Subject: [PATCH v2 1/7] char: xillybus: Improve control of execution flow with mutexes Date: Wed, 22 Jul 2026 12:23:01 +0200 Message-Id: <20260722102307.49090-2-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260722102307.49090-1-eli.billauer@gmail.com> References: <20260722102307.49090-1-eli.billauer@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: This commit addresses two issues by using mutexes: (1) Add a mutex to protect the fifo_buf_order global variable. The purpose of this variable is avoid repeated failed calls to __get_free_pages() for allocating FIFO memory, when the chunk size was too big. However, if two drivers are initialized at the same time, fifo_init() may run in parallel, and fifo_buf_order may be reduced too much. This is a far-fetched scenario, now completely prevented by fifo_buf_order_mutex. (2) setup_channels() acquires process_in_mutex to prevent process_bulk_in() from accessing the xillyusb_dev struct. With correctly working hardware, process_bulk_in() is never called while setup_channels() runs, because the device has no reason to send data in that phase. The mutex ensures that process_bulk_in() does not touch the members that setup_channels() alters. There is no similar protection for data flow in the other direction, because during the setup process, the only outbound data is the BULK endpoint used for commands, and it remains untouched after its initial setup. Signed-off-by: Eli Billauer --- Notes: No change on v1->v2. drivers/char/xillybus/xillyusb.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/drivers/char/xillybus/xillyusb.c b/drivers/char/xillybus/xillyusb.c index 34e7ad3bcab3..a28e6416cb01 100644 --- a/drivers/char/xillybus/xillyusb.c +++ b/drivers/char/xillybus/xillyusb.c @@ -50,6 +50,7 @@ MODULE_LICENSE("GPL v2"); static const char xillyname[] = "xillyusb"; static unsigned int fifo_buf_order; +static DEFINE_MUTEX(fifo_buf_order_mutex); static struct workqueue_struct *wakeup_wq; #define USB_VENDOR_ID_XILINX 0x03fd @@ -375,6 +376,8 @@ static int fifo_init(struct xillyfifo *fifo, unsigned int log2_fifo_buf_size; + guard(mutex)(&fifo_buf_order_mutex); + retry: log2_fifo_buf_size = fifo_buf_order + PAGE_SHIFT; @@ -1943,6 +1946,9 @@ static int setup_channels(struct xillyusb_dev *xdev, struct xillyusb_channel *chan, *new_channels; int i; + /* Don't let process_bulk_in() run while we change the channels */ + guard(mutex)(&xdev->process_in_mutex); + chan = kzalloc_objs(*chan, num_channels); if (!chan) return -ENOMEM; -- 2.34.1