From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-lf1-f49.google.com (mail-lf1-f49.google.com [209.85.167.49]) (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 B7CF236BCC9 for ; Tue, 30 Jun 2026 09:24:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.49 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782811453; cv=none; b=MDBBaCxeE+qCNJTdUyjzuEe8ucN/P0iPEus2yb0KC9ba/+z6WQLJWaZwM6FpBBYLKv5oWxuqt6sGXb1QvodyuejCWoNjNuy3+3TjYMToTda/nFUUAw58fUJl+XS7hbOZwziCWgxlaueD3ejzQsGjN+9pytw8VmUE+VmyEmyNIwA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1782811453; c=relaxed/simple; bh=xOxh7TaijDcqO9RnOp0BHsRBCoNB4olGuy7mNwOF/uI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=Qdm4c52KW1SPAa5eN6pL2S89SxAgLT+3EiwmBSDIceHjZS7N9RM68DyUeR1UmB92fyzYfIm5jKZXWD9EZZXYLMgy1cV655IBPvI+QrBOf/icapbqSuRSk8Bn8cgOOMQs2l0A1YSYD+3hMt0VO4tsRC27BAvFNMqwfdEXh2EcK4k= 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=Soug56Tb; arc=none smtp.client-ip=209.85.167.49 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="Soug56Tb" Received: by mail-lf1-f49.google.com with SMTP id 2adb3069b0e04-5aeba09900bso1463144e87.2 for ; Tue, 30 Jun 2026 02:24:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1782811447; x=1783416247; 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; bh=Nr6wOR8nNMvmdFiv9SDJN2VRKevR2WA/h8PdIDNGTqg=; b=Soug56TbXuq184x2WQxTyxzjwdYNN2GtS631sbqEVvWKI5Xq01ZHIhEac5lC8BuYxj IlJMi2GZVOJJO6RJAnUt0q4bYM1zItBA9x72s5hGwJblcARCvTFpzlo4SL4Bh2M6pxXO KJpvWXywib/LQYP3esypKTuJC7hCyCvZbwj5URjWg2tNBv0rc8e9Oxtme009HC5+tIF7 MLReR0Ras5Gxw/bU0d35sp1rl04Gnp2tEQ6SvHTNO0oCCVaxb5Zs5Af48MhtttmayhVQ FZqcFf+37UQke6NBRMmRULii+ybVoikS9mTShX7O1ECW5hlN5XyEcNRLgr54+xKcrL1o mNhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1782811447; x=1783416247; 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; bh=Nr6wOR8nNMvmdFiv9SDJN2VRKevR2WA/h8PdIDNGTqg=; b=Bh3cKnr9XRL4KesT8rRHnvm9jBwL21uoJZFd49dNp9iDwLxizceBysQgIa+TT0Nbnr 37Hy4ShyimdfEkKxuQkM6RxZCqrVDvpP0KJCrBbOsRe8fAWUpRsE33VYZKI2Bsd05rGb vHA5iU9ZXU0664Puthiobn9es4SA5ATaeLtgaUOSOErJrtarAciH0cVIxDKHM0GGAr4K MiVLkzt+AEiLK5OgJdxx2yx1LvwDIdJFo9S9Kf7X78vONi3+hze7mTwWvvS+g+gPIZHv VZn8L7PHG1pnVXONrr+gSAdCmPuzL3jmHLZOE2ys7H1u16YJPvz3ygt9mhtzSOEOJQg8 49ow== X-Forwarded-Encrypted: i=1; AHgh+RpY4ZBv2m9mBmUP0eW2wJerI5NOeQPGkKNRFmp2FGO6PUB78ICS4dQwiogqOzTLRK3i8qHrP7hB+IQB2mk=@vger.kernel.org X-Gm-Message-State: AOJu0Yxx6Fp8J92kGs2jSFgujS3LtULt3Zr2UL3dIQvYtsUlrIp5ndby bRFvdKcyS2W1AvHVrgyx/aA4BD+G7C1l9SspScle12hitJOxyWL4cEjK X-Gm-Gg: AfdE7cm5rfumGwj9TYIX8w8DdUb4ayhjUf+LiDNb4b7vGzeeCqQyY4yOo01IQDr5ua7 +pf9fsMJ3+RzzgkuJf0gEArJJbQzDbQSnd/4VoG55yBZ4dtv37zg3BriwDZULK747y7/xibkuMW h92UIT7uok5GZmFsN7e/oqnfmiK6EH8GRAm8fy0Cuw8gXuxVzDZ+GKedr/xGuFmC6cYDc7GRWMF GX0sRdLRlncIjWjR6yedlDWWQru4yGHfNGr+q50H8nYzIxQ7Dbci7Lv69DiIAzIO7rKAu2lACSB w7mGsvPSKxk6O6EJrzFXHrdZkPVrmSqVCLA+42Wq90ESX+JLS//3gYqAq8Ol68yfA/ekJCDa+Qc p3SVOnYseYVS+VTORHQqKwBdMG/Sd8Q+3oVHTzYNmO1eBTAGiT/nqN0FKL3IaQ1PS4e6ojhCvNg kD3ms7JdsZdrJap/D/twL3x0JshBb6Wpq0mVb+iw6h X-Received: by 2002:a05:6512:1418:b0:5ae:b8cc:7091 with SMTP id 2adb3069b0e04-5aebdb8e2demr777054e87.11.1782811447155; Tue, 30 Jun 2026 02:24:07 -0700 (PDT) Received: from localhost (c-85-228-45-68.bbcust.telenor.se. [85.228.45.68]) by smtp.gmail.com with ESMTPSA id 2adb3069b0e04-5aebe33cebbsm430754e87.20.2026.06.30.02.24.04 (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 30 Jun 2026 02:24:05 -0700 (PDT) From: Eli Billauer To: gregkh@linuxfoundation.org Cc: arnd@arndb.de, linux-kernel@vger.kernel.org, Eli Billauer Subject: [PATCH 1/7] char: xillybus: Improve control of execution flow with mutexes Date: Tue, 30 Jun 2026 11:23:24 +0200 Message-Id: <20260630092330.43534-2-eli.billauer@gmail.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20260630092330.43534-1-eli.billauer@gmail.com> References: <20260630092330.43534-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 --- 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